Qt retrieve QFlags form QVariant

551 views Asked by At

Here is a code exemple:

#include <QDebug>

enum Pouet
{
    F1 = 1,
    F2 = 2,
    F3 = 4,
};
Q_DECLARE_FLAGS(Pouets, Pouet)
Q_DECLARE_METATYPE(Pouets)
Q_DECLARE_OPERATORS_FOR_FLAGS(Pouets)

int main(int argc, char *argv[])
{

    Pouets p = F1|F3;
    qDebug()<<p;
    qDebug()<<QVariant(p).toString();
    qDebug()<<QVariant(QVariant(p).toString()).value<Pouets>();

}

Output:

QFlags(0x1|0x4)
"5"
QFlags()

Please, what is wrong here? I simply can't retrieve a QFlag previously stored in a QVariant?

0

There are 0 answers