Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFlags usage
Qt 6.11 is out! See what's new in the release blog

QFlags usage

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 603 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by Anonymous_Banned275
    #1

    **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.

    A 1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #2

      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.

      1 Reply Last reply
      1
      • A Anonymous_Banned275

        **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.

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved