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. Q_FLAGS in namespace causes QtCreator to mark line as error
Forum Updated to NodeBB v4.3 + New Features

Q_FLAGS in namespace causes QtCreator to mark line as error

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views 1 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.
  • D Offline
    D Offline
    DerManu
    wrote on last edited by
    #1

    Hi there,
    just stumbled on something strange in my code. I have a namespace, in the namespace I define an enum for a QFlags type, so there's something like this:
    @
    namespace Test
    {
    enum MyEnum {meOne=0x01, meTwo=0x02};
    Q_FLAGS(MyEnum MyEnums)
    Q_DECLARE_FLAGS(MyEnums, MyEnum)
    }
    Q_DECLARE_OPERATORS_FOR_FLAGS(Test::MyEnums)
    @

    And this compiles just fine. However, in QtCreator, the line with Q_FLAGS is underlined red and the tool tip says "expected a declaration". What's up with that? Why does it compile fine but QtCreator thinks it won't? After all, the Q_FLAGS macro expands to nothing and is only used by moc.
    Q_FLAGS inside classes work fine, it seems the namespace is a necessary condition for this phenomenon. Maybe because moc can't access namespace ("classless") flags/enums and QtCreator knows about that? Why not say it in the tool tip then?

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

      Q_FLAGS only makes sense within a QObject subclass.
      See the docs for Q_FLAGS and the example there.

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Place #include <QObject> in the top of the file. That might do the trick.
        Remember that a compiler will use totally different settings then what QtCreator might show. QtCreator is just a handy tool that shows what "might" be wrong or what is wrong from the output of the compiler. Also a new qmake run might do the trick.
        Greetz

        Greetz, Jeroen

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          including<QObject> didn't work, neither the qmake run.

          I suppose it really is that Q_FLAGS only makes sense in QObject-derived classes. I did know that, however, I didn't expect QtCreator to mark something as wrong if the compiler doesn't mind, and secondly then output an inappropriate tooltip.

          Thanks for your suggestions!

          1 Reply Last reply
          0

          • Login

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