QFlags usage
-
**EDIT
This is a bad idea , please ignore BEFORE I delete it.**
I am going to utilize QFlags to identify specific class / object.
I am looking into this example to define my own flags
https://doc.qt.io/qt-6/qflags.html#details
class MyClass { public: enum Option { NoOptions = 0x0, ShowTabs = 0x1, ShowAll = 0x2, SqueezeBlank = 0x4 }; Q_DECLARE_FLAGS(Options, Option) ... }; Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options)
and I do not understated where to define this "custom flags " optional class MyClassclass.
I like to identify my objects which are used as a library in my subdirs project .
Hence I would prefer to have the this optional class MyClassclass as as a library so it can be used / accessed by
them. -
Does MyClass contain anything other than the enum and two related Q_* macros?
If it is only that, then the class is entirely self-contained in the header (all the needed functions to support QFlag are inlined) and there are no sources to add to a library project. Assuming that other things in your library use MyClass, the header should be part of the headers that go with the library. A user of MyClass can create an instance after including the header.
If there is any other non-inlined code in the MyClass then its corresponding source file should be included in the library. A user of MyClass needs to include the header in their source and link the library before they can create an instance of the class.
-
**EDIT
This is a bad idea , please ignore BEFORE I delete it.**
I am going to utilize QFlags to identify specific class / object.
I am looking into this example to define my own flags
https://doc.qt.io/qt-6/qflags.html#details
class MyClass { public: enum Option { NoOptions = 0x0, ShowTabs = 0x1, ShowAll = 0x2, SqueezeBlank = 0x4 }; Q_DECLARE_FLAGS(Options, Option) ... }; Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options)
and I do not understated where to define this "custom flags " optional class MyClassclass.
I like to identify my objects which are used as a library in my subdirs project .
Hence I would prefer to have the this optional class MyClassclass as as a library so it can be used / accessed by
them.@AnneRanch
You can also use QFlags on enums outside classes, and better still, on scoped enums, like so:enum class EMyOption : int { NoOptions = 0x0, ShowTabs = 0x1, ShowAll = 0x2, SqueezeBlank = 0x4 }; Q_DECLARE_FLAGS(MyOptions, EMyOption) Q_DECLARE_OPERATORS_FOR_FLAGS(MyOptions) Q_DECLARE_METATYPE(EMyOption) Q_DECLARE_METATYPE(MyOptions)
That's header-only - no need for a source file.