Results 1 to 5 of 5

Thread: How to find the Qsettings is exists or not?

  1. #1
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default How to find the Qsettings is exists or not?

    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","NamedUserNam e");
    qAppSetUser.setValue("AccessLevel","Level1");

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

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find the Qsettings is exists or not?

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2016
    Posts
    53
    Thanks
    13
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: How to find the Qsettings is exists or not?

    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.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,459
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to find the Qsettings is exists or not?

    Read more about QSettings especially about QSettings::contains.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find the Qsettings is exists or not?

    Quote Originally Posted by Mathan View Post
    If the file is not, I am trying to access, will not throw an error?
    It will not throw an error.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. detect if a URL exists or not
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 27th January 2013, 13:16
  2. File exists on server
    By Chops211 in forum Qt Programming
    Replies: 5
    Last Post: 6th August 2011, 20:22
  3. Replies: 2
    Last Post: 21st February 2011, 14:52
  4. Replies: 1
    Last Post: 14th January 2011, 11:57
  5. Does anyone know if anything like this exists for Qt
    By Jachyra in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2007, 22:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.