Results 1 to 4 of 4

Thread: QSettings::value() does not return value.

  1. #1
    Join Date
    Jun 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSettings::value() does not return value.

    Hello fellow QT devs.

    Here goes my problem:

    I have QStringList which contains strings of registry paths
    i.e.
    \Profile Name\Info\Name
    \Profile Name\Info\Lenght
    \Profile Name\Size\Width
    \Profile Name\Size\Height
    and so on..

    I need to get values from those paths
    Qt Code:
    1. ...
    2. QSettings settings;
    3. QStringList keys = settings.allKeys();
    4.  
    5. settings.beginReadArray("Profile Name");
    6.  
    7. for(int i = 0; i < keys.size(); i++)
    8. {
    9. QString key = keys.at(i);
    10. QVariant value = settings.value(key, QVariant::Invalid);
    11. ...
    12. }
    13. ...
    To copy to clipboard, switch view to plain text mode 

    That's the code I'm trying to use. value() does not return the proper value(no value returned at all!).How can I get the value-function to return the value of that specific key?

    Your help is appreciated.


    - Eeli Reilin

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSettings::value() does not return value.

    Hi,

    #
    QSettings settings;
    #
    QStringList keys = settings.allKeys();
    #

    #
    settings.beginReadArray("Profile Name");
    You are getting the strings from "settings" variable and it has any string yet. Then you insert "Profile Name" to settings and you think that "keys" will auto update the readed value.

    Qt Code:
    1. QSettings settings;
    2. settings.beginReadArray("Profile Name"); //First you have to write the strings
    3. QStringList keys = settings.allKeys(); //then you can obtain them
    4.  
    5. for(int i = 0; i < keys.size(); i++)
    6. {
    7. QString key = keys.at(i);
    8. QVariant value = settings.value(key, QVariant::Invalid);
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jun 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: QSettings::value() does not return value.

    Quote Originally Posted by ^NyAw^ View Post
    Hi,



    You are getting the strings from "settings" variable and it has any string yet. Then you insert "Profile Name" to settings and you think that "keys" will auto update the readed value.

    Qt Code:
    1. QSettings settings;
    2. settings.beginReadArray("Profile Name"); //First you have to write the strings
    3. QStringList keys = settings.allKeys(); //then you can obtain them
    4.  
    5. for(int i = 0; i < keys.size(); i++)
    6. {
    7. QString key = keys.at(i);
    8. QVariant value = settings.value(key, QVariant::Invalid);
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    Yea, but the values are already in the registry
    value() always returns the default value, which is in my case QVariant::Invalid

    Damnit, why is this so damn hard?


    - Eeli Reilin

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings::value() does not return value.

    Quote Originally Posted by zEeLi View Post
    Yea, but the values are already in the registry
    value() always returns the default value, which is in my case QVariant::Invalid

    Damnit, why is this so damn hard?
    The thing is that you do not supply a valid registry path to QSettings constructor... Do you expect it to automagically figure out where your settings are stored? Basically, when you don't pass any parameters to QSettings ctor it does automagically find a location to store them but I doubt it's the one you expect...
    Last edited by fullmetalcoder; 11th June 2007 at 10:26. Reason: spelling error
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. [SOLVED] DirectShow Video Player Inside Qt
    By ToddAtWSU in forum Qt Programming
    Replies: 16
    Last Post: 3rd November 2011, 07:47
  2. Invalid return type
    By Salazaar in forum Newbie
    Replies: 3
    Last Post: 5th June 2007, 17:51
  3. qt 4.2.2 install in tru64 cxx
    By try to remember in forum Installation and Deployment
    Replies: 0
    Last Post: 30th March 2007, 07:43
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  5. Version 4.1.3 and QTreeView
    By greencastor in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 10:37

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.