Results 1 to 4 of 4

Thread: Storing and Retrieving a QFlags

  1. #1
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Storing and Retrieving a QFlags

    I want to be able to store a QFlags variable in a database and then retrieve it later on.

    I have an enum of weekdays like this:
    Qt Code:
    1. enum Weekday {
    2. NoWeekday = 0x0,
    3. Monday = 0x1,
    4. Tuesday = 0x2,
    5. Wednesday = 0x4,
    6. Thursday = 0x8,
    7. Friday = 0x16,
    8. Saturday = 0x32,
    9. Sunday = 0x64
    10. };
    11. Q_DECLARE_FLAGS(Weekdays, Weekday);
    12.  
    13. class MyClass
    14. {
    15. public:
    16. Weekdays days;
    17. void save() {
    18. days = Monday | Thursday;
    19. //I can convert 'days' into an int no problem here
    20. }
    21. void load() {
    22. //How do I convert my stored int back into a Weekdays QFlags?
    23. }
    24. };
    To copy to clipboard, switch view to plain text mode 

    I've looked through the docs on QFlags and QVariant but can't find anything pertinent.

    I'm using my own enum instead of Qt::dayOfWeek because I need to have an OR'd combination of weekdays instead of just a single one.

    Another way I thought of doing this is with a QBitArray the way Kde4 does it in their libkdepim library but I don't know how to store (or serialize) a QBitArray.

    I'm using QSqlQuery to select and insert my data into a database.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and Retrieving a QFlags

    Qt Code:
    1. days = (Weekdays)intValue;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2006
    Posts
    70
    Thanks
    12
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and Retrieving a QFlags

    See thats why coding by yourself for hours on end until you go crosseyed is a bad idea.

    Thanks for bringing my mind out of it's jellied state and showing me the most obvious solution!

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing and Retrieving a QFlags

    You're welcome!

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.