PDA

View Full Version : Issue with Qsettings



MM5
18th July 2015, 16:55
Hi,

I have a problem that I can't find the ini file and it seems that even the default settings are not set.
The declaration:


QSettings *p_projsettings;

After it I expect the File created


p_projsettings = new QSettings("c:temp\MySoft\DCP_MON_INI.ini", QSettings::IniFormat);


defaultvalues();
p_projsettings->sync();
if(p_projsettings->status()==QSettings::NoError)
{
retval=false;
}
else
{
retval=true;
}
qDebug() << "Status ProjSettings:" << retval;
return (retval);

The status is alway false


void INI_FILE::defaultvalues()
{
p_projsettings->value("BAUD","230400");
p_projsettings->value("PORT","COM3");
p_projsettings->value("PARITY","NONE");
p_projsettings->value("DATABIT","8");
p_projsettings->value("STOPBIT","1");
p_projsettings->value("FLOWCONTROL","FLOW_OFF");
p_projsettings->value("TIMEOUT","150");
// qDebug("projsettings BAUD",projsettings->value("BAUD"));
qDebug() << "projsettings BAUD:" << p_projsettings->value("BAUD").toString();
p_projsettings->sync();
}

Could anybody please tell me what is wrong?

Thanks!

ars
18th July 2015, 17:08
Hello,


p_projsettings = new QSettings("c:temp\MySoft\DCP_MON_INI.ini", QSettings::IniFormat);

The path to your ini file does not exist. You use \ in string constant. Better use / for path separator or, if you insist on using \ as path separator, you have to escape the \ in the string constant, i.e. replace each \ in your path by \\, i.e.

p_projsettings = new QSettings("c:temp\\MySoft\\DCP_MON_INI.ini", QSettings::IniFormat);

Best regards
ars

anda_skoa
18th July 2015, 17:21
if(p_projsettings->status()==QSettings::NoError)
{
retval=false;
}

The status is alway false

that's good, isn't it? false is the value you assign to retval if there are no errors.



and it seems that even the default settings are not set.

Do you set any default values?




void INI_FILE::defaultvalues()
{
p_projsettings->value("BAUD","230400");
p_projsettings->value("PORT","COM3");
p_projsettings->value("PARITY","NONE");
p_projsettings->value("DATABIT","8");
p_projsettings->value("STOPBIT","1");
p_projsettings->value("FLOWCONTROL","FLOW_OFF");
p_projsettings->value("TIMEOUT","150");
// qDebug("projsettings BAUD",projsettings->value("BAUD"));
qDebug() << "projsettings BAUD:" << p_projsettings->value("BAUD").toString();
p_projsettings->sync();
}

What is the purpose of this method?
Reading a bunch of keys but not using the read values doesn't strike me as particularily useful.

Cheers,
_

MM5
18th July 2015, 18:01
Do you set any default values?


What is the purpose of this method?
Reading a bunch of keys but not using the read values doesn't strike me as particularily useful.

Cheers,

Thank you for the quick responce!

So far I remember the value function, it delivers the value out of seetings or if not exist it uses the default... but yes you are right somehow I have to write the settings.
I'll look into it...

Thank you very much !
BR

Added after 22 minutes:

Solved :-) Thanks to the replies!

BR
MM

ChrisW67
19th July 2015, 06:11
p_projsettings = new QSettings("c:temp\MySoft\DCP_MON_INI.ini", QSettings::IniFormat);

Even with the backslashes properly escaped or replaced with forward slashes (as Ars pointed out) this may still be interpreted as a path that is relative to the current directory on drive C:. Perhaps you should say:


p_projsettings = new QSettings("c:\\temp\\MySoft\\DCP_MON_INI.ini", QSettings::IniFormat);