Results 1 to 2 of 2

Thread: Store an custom enum in QSettings

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Store an custom enum in QSettings

    Hi,

    how to store an custom enum with QSettings and restore it?

    Qt Code:
    1. myClass::myEnum m_enum = settings.value("xxx").value<myClass::myEnum>(); // fails because no Qt-class
    To copy to clipboard, switch view to plain text mode 


    Thanks
    Lykurg

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

    Default Re: Store an custom enum in QSettings

    There are a few choices... The simplest is to cast your enum to int (and vice versa). If you need something more complicated, you can use Qt object introspection to map from your enum to QString - there even is a thread that discusses this in this forum. Remember, that if you want to use your custom type with QVariant directly, you have to first register it with the meta-type system. It's described in QVariant docs.

  3. The following user says thank you to wysota for this useful post:

    Lykurg (15th March 2007)

Similar Threads

  1. enum property
    By illuzioner in forum Qt Tools
    Replies: 10
    Last Post: 22nd August 2006, 21:47

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.