Results 1 to 14 of 14

Thread: QSettings

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    South Carolina, USA
    Posts
    34
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings

    Quote Originally Posted by incapacitant
    I am using :
    Qt Code:
    1. settings.value( "coco", "ERROR" ).toString();
    To copy to clipboard, switch view to plain text mode 
    this works

    Qt Code:
    1. const QString s = "coco";
    2. 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:
    Qt Code:
    1. #include <QString>
    2. #include <QSettings>
    3. #include <iostream>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QSettings settings("TestSoft", "QSettings Test");
    8. settings.setValue("testName", 100);
    9. const QString s = "testName";
    10. std::cout << "Test call with char string: "
    11. << settings.value("testName", "ERROR").toString().toStdString() << std::endl
    12. << "Test call with QString: "
    13. << settings.value(s, "ERROR").toString().toStdString() << std::endl
    14. << "For good measure create error: "
    15. << settings.value("doesNotExist", "ERROR").toString().toStdString() << std::endl;
    16. char t;
    17. std::cin >> t;
    18. return 0;
    19. }
    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
    Last edited by michael; 24th May 2006 at 20:49.

  2. The following user says thank you to michael for this useful post:

    incapacitant (24th May 2006)

Similar Threads

  1. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 07:26
  2. Replies: 4
    Last Post: 1st February 2006, 17:17
  3. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58
  4. QSettings - beginReadArray not working
    By Mike in forum Qt Programming
    Replies: 7
    Last Post: 9th January 2006, 21:24

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.