文档:http://doc.qt.io/qt-5/qflags.html#operator-int
问题。我想知道哪些标志是用inter测试一个一个,所以我想要int编号。谁能提供一个如何在QFLAGS的众多QT方法之一中使用该操作员的示例?
通过参考QFlags.h
源代码(https://android.googlesource.com/platform/prebuilts/prebuilts/android-emulator-emulator-emulator-build/qt//master/master/common/common/common/common/common/incinclude/qtcore/qflags.h(
这是" int"运算符qflags中的定义。
Q_DECL_CONSTEXPR inline operator Int() const Q_DECL_NOTHROW { return i; }
和返回语句中的" i"被声明为
Int i;
和" int"被声明为
typedef int Int
请注意以下QFlags
的两个构造函数。第一个构造函数将Enum
作为参数,第二个构造函数将QFlag
作为参数。
Q_DECL_CONSTEXPR inline QFlags(Enum f) Q_DECL_NOTHROW : i(Int(f)) {}
Q_DECL_CONSTEXPR inline QFlags(QFlag f) Q_DECL_NOTHROW : i(f) {}
注意到上述构造函数后,如果将Enum
传递给构造函数,则枚举可以是signed
ONE或unsigned
。QFlags
内部类型使用Int
将其施放为int
。
现在考虑以下示例。
//Qt::CursorShape is an Enum
Qt::CursorShape shape = Qt::ArrowCursor;
//Create QFlags object by passing "ENUM" as parameter
QFlags<Qt::CursorShape> qF(shape);
//Create QFlags object by just passing FLAG as a parameter
QFlags<Qt::CursorShape> q(Qt::ArrowCursor);
现在称为" int"运算符的情况:在下面的代码中,第一个语句调用Int
运算符,而不是在第二个语句中调用。
//Now try getting the values.
int test = qF; //In this case the "Int" operator is called.
int test1 = q;