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.