![Quote](images/misc/quote_icon.png)
Originally Posted by
incapacitant
I am using :
settings.value( "coco", "ERROR" ).toString();
settings.value( "coco", "ERROR" ).toString();
To copy to clipboard, switch view to plain text mode
this works
settings.value( s, "ERROR" ).toString();
const QString s = "coco";
settings.value( s, "ERROR" ).toString();
To copy to clipboard, switch view to plain text mode
this insists on returning "ERROR"
Is there a way to pass a variable to settings.value ?
s being a const string
const QString works for me on (Qt 4.1.3 / WindowsXP / Visual Studio 2005) and (Qt 4.0.1 / WindowsXP / mingw - g++)
Here is the code:
#include <QString>
#include <QSettings>
#include <iostream>
int main(int argc, char *argv[])
{
QSettings settings
("TestSoft",
"QSettings Test");
settings.setValue("testName", 100);
std::cout << "Test call with char string: "
<< settings.value("testName", "ERROR").toString().toStdString() << std::endl
<< "Test call with QString: "
<< settings.value(s, "ERROR").toString().toStdString() << std::endl
<< "For good measure create error: "
<< settings.value("doesNotExist", "ERROR").toString().toStdString() << std::endl;
char t;
std::cin >> t;
return 0;
}
#include <QString>
#include <QSettings>
#include <iostream>
int main(int argc, char *argv[])
{
QSettings settings("TestSoft", "QSettings Test");
settings.setValue("testName", 100);
const QString s = "testName";
std::cout << "Test call with char string: "
<< settings.value("testName", "ERROR").toString().toStdString() << std::endl
<< "Test call with QString: "
<< settings.value(s, "ERROR").toString().toStdString() << std::endl
<< "For good measure create error: "
<< settings.value("doesNotExist", "ERROR").toString().toStdString() << std::endl;
char t;
std::cin >> t;
return 0;
}
To copy to clipboard, switch view to plain text mode
This is the output:
C:\...>qsettings.exe
Test call with char string: 100
Test call with QString: 100
For good measure create error: ERROR
exit
C:\...>
I hope this helps you. If you want to compile the code above don't forget to add the following to the *.pro file as this is a console application.
CONFIG += console
-Michael
Bookmarks