When using Qt, many functions take an argument like the flag Qt::LeftDockWidgetArea.
Even though I looked through the Qt sources I could not understand how to achieve
this naming behaviour. Is it general C++ or Qt specific?
Assume I have a class MyClass:
class MyClass {
public:
MyClass();
void setFlag(???);
};
I want to call the setFlag method like this:
MyClass mc;
mc.setFlag(MyClass::flag1 | MyClass::flag2)
flag1 and flag2 should just be 0x01 & 0x02, is this an enum?
Where do I have to declare that?
And what is the argument of the method?
I’m sorry if this is obvious, but I don’t get it.
SOLUTION (from the answers)
Very good. From reading the answers below I added this:
(note that I didn’t really needed flags, just the numbers from an enum, this simplified it a lot)
namespace MyNames {
typedef enum {
FA = 0,
FB = 1
} Field;
}
class MyClass
{
public:
MyClass();
char getField(MyNames::Field f) const;
};
This indeed allows the following calls (not):
mc.getField(MyNames::FA) //OK
mc.getField(1) //not OK
You will find this (or something similar) in
src\corelib\global\qnamespace.h:This usually becomes simply
To refer to a name declared inside this
Qtnamespace (such asLeftDockWidgetArea), you precede it withQt::.