darkadept
4th October 2007, 18:13
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:
enum Weekday {
NoWeekday = 0x0,
Monday = 0x1,
Tuesday = 0x2,
Wednesday = 0x4,
Thursday = 0x8,
Friday = 0x16,
Saturday = 0x32,
Sunday = 0x64
};
Q_DECLARE_FLAGS(Weekdays, Weekday);
class MyClass
{
public:
Weekdays days;
void save() {
days = Monday | Thursday;
//I can convert 'days' into an int no problem here
}
void load() {
//How do I convert my stored int back into a Weekdays QFlags?
}
};
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.
I have an enum of weekdays like this:
enum Weekday {
NoWeekday = 0x0,
Monday = 0x1,
Tuesday = 0x2,
Wednesday = 0x4,
Thursday = 0x8,
Friday = 0x16,
Saturday = 0x32,
Sunday = 0x64
};
Q_DECLARE_FLAGS(Weekdays, Weekday);
class MyClass
{
public:
Weekdays days;
void save() {
days = Monday | Thursday;
//I can convert 'days' into an int no problem here
}
void load() {
//How do I convert my stored int back into a Weekdays QFlags?
}
};
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.