[Qt-interest] copy of windows registry file

Stephen Jackson spjackson42 at gmail.com
Sat Dec 5 17:44:10 CET 2009


2009/12/5 navid navid :
>
> how can I prepare  a copy from windows registry file?
> the following code does not work:
>
> [CODE]
> QSettings _qsetsettings("ORG_NAME", "APP_NAME");
> ...
> bool _bres = QFile::copy(_qsetsettings.fileName(), _qsname);
> qDebug()<<"source: "<<_qsetsettings.fileName()
>        <<" dest: "<<_qsname
>        <<" Res: "<<_bres;
> [/CODE]
>
>
> Application output:
> source:  "\HKEY_CURRENT_USER\Software\ORG_NAME\APP_NAME"  dest:  "G:/qt/prj/debug/settings.txt"  Res:  false
>

QFile::copy won't work because _qsetsettings.fileName() "a system
registry path, not a file path". I don't think there is a way to do
this without copying the individual keys yourself, e.g.

#include <QtGui>

int main()
{
	QSettings input("ORG_NAME", "APP_NAME");
	QSettings output("./foo.ini", QSettings::IniFormat);
	QStringList keys = input.allKeys();

	foreach( QString key, keys )
	{
		output.setValue(key, input.value(key));
	}

	return 0;
}

-- 
Cheers,

Stephen Jackson




More information about the Qt-interest-old mailing list