PDA

View Full Version : How to find the Qsettings is exists or not?



Mathan
19th September 2016, 11:10
Hi,

I would like to setup an Qsetting which stores like username, theme the user used.
Before accessing the Qsetting, I want to Qsetting is present or I will create a new considering user login first time.



Code snippet:
QCoreApplication::setOrganizationName("gghh");
QCoreApplication::setOrganizationDomain("gghh.COM");
QCoreApplication::setApplicationName("Library");
QCoreApplication::setApplicationVersion("1.0");

QSettings qAppSetUser;
qAppSetUser.setValue("UserName",pstrUserName);
qAppSetUser.setValue("Password",pstrPassword);
qAppSetUser.setValue("NamedUserName","NamedUserName");
qAppSetUser.setValue("AccessLevel","Level1");

Query: How to check the Qsetting - qAppSetUser is already exist or not/

Thanks in advance.

wysota
19th September 2016, 11:32
You don't have to do the check. Just open QSettings object and try to read value for e.g. "UserName" key. If it's not there then the file is not present.

Mathan
19th September 2016, 13:11
Hi,

Thanks for the reply,

If the file is not, I am trying to access, will not throw an error? Could you pls share the code snippet, If you have.

Lesiok
19th September 2016, 15:39
Read more about QSettings especially about QSettings::contains.

wysota
20th September 2016, 09:17
If the file is not, I am trying to access, will not throw an error?

It will not throw an error.