Results 1 to 5 of 5

Thread: Save enums in QSettings

  1. #1

    Default Save enums in QSettings

    Hi!
    How I Can Save enums in QSettings???
    And
    I Have A Form With 4 Child Window
    How I Can Save All Child Windows Settings Such as (size, pos, ...)???

    Thanks.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save enums in QSettings

    Quote Originally Posted by redhat View Post
    Hi!
    How I Can Save enums in QSettings???
    you can cast enum value to QString and then write it using QSettings.
    Quote Originally Posted by redhat View Post
    And
    I Have A Form With 4 Child Window
    How I Can Save All Child Windows Settings Such as (size, pos, ...)???

    Thanks.
    there is method only for QMainWindow
    QByteArray QMainWindow::saveState ( int version = 0 ) const
    in anohter case you need to do this manually.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3

    Default Re: Save enums in QSettings

    Thanks for Your Response.
    How I can cast a enum to QString???

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save enums in QSettings

    you can do this using this method
    QString::number
    Returns a string equivalent of the number n according to the specified base.
    or can do this
    Qt Code:
    1. enum MyEnum {MyValue, ....};
    2. ...
    3. QSettings settings("test.ini", QSettings::IniFormat);
    4. settings.setValue("MyEnumValue", MyValue);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    in result you'll get in ini-file
    [General]
    MyEnumValue=0
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: Save enums in QSettings

    You could also make it as follows:

    Qt Code:
    1. enum MyEnum {MyValue...};
    2. Q_ENUMS(MyEnum);
    3. .
    4. .
    5. .
    6. QString enum2Str(MyEnum value, const QString &enumName = "MyEnum") {
    7. const QMetaObject &mo = SetupExporter::staticMetaObject;
    8. int index = mo.indexOfEnumerator(enumName.toLatin1().constData());
    9. QMetaEnum metaEnum = mo.enumerator(index);
    10. return QString(metaEnum.valueToKey(value));
    11. }
    12. .
    13. .
    14. .
    15. QSettings settings("test.ini", QSettings::IniFormat);
    16. settings.setValue(enum2Str(MyValue), MyValue);
    To copy to clipboard, switch view to plain text mode 

    Regards
    NoRulez

Similar Threads

  1. QSettings problem?
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 28th June 2008, 21:14
  2. QSettings does not save...
    By mtrpoland in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2007, 12:15
  3. What does "Save All" actually save?
    By Mariane in forum Newbie
    Replies: 7
    Last Post: 31st January 2006, 13:23

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.