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. About Q_OBJECT question
Forum Updated to NodeBB v4.3 + New Features

About Q_OBJECT question

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 243 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.
  • K Offline
    K Offline
    kdrpro1
    wrote on last edited by
    #1

    There is Q_OBJECT in my code. If it is written entirely in main.cpp and is not divided into three files, an error will occur. Is this a rule for Q_OBJECT?

    Pl45m4P C 2 Replies Last reply
    0
    • K kdrpro1

      There is Q_OBJECT in my code. If it is written entirely in main.cpp and is not divided into three files, an error will occur. Is this a rule for Q_OBJECT?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @kdrpro1 said in About Q_OBJECT question:

      There is Q_OBJECT in my code

      What Q_OBJECT? The macro is in your main.cpp? Or one QObject object?

      If it is written entirely in main.cpp and is not divided into three files

      Q_OBJECT based classes need to be interpreted by MOC (Meta-Object-compiler). You can't moc your main function, if that is what you are asking.

      Is this a rule for Q_OBJECT?

      Have a look at the QObject documentation... it's the basis of the Qt Framework

      • https://doc.qt.io/qt-6/qobject.html#details
        • https://doc.qt.io/qt-6/qobject.html#Q_OBJECT

      Here are some "rules" and how it works:

      • https://doc.qt.io/qt-6/metaobjects.html

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      jeremy_kJ 1 Reply Last reply
      0
      • K kdrpro1

        There is Q_OBJECT in my code. If it is written entirely in main.cpp and is not divided into three files, an error will occur. Is this a rule for Q_OBJECT?

        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        @kdrpro1 said in About Q_OBJECT question:

        There is Q_OBJECT in my code.
        If it is written entirely in main.cpp and is not divided into three files,
        an error will occur.

        It would be really helpful for you to have posted an example of your actual code and the actual error.

        Is this a rule for Q_OBJECT?

        No, as a rule Q_OBJECT is not supposed to generate "an error".

        1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @kdrpro1 said in About Q_OBJECT question:

          There is Q_OBJECT in my code

          What Q_OBJECT? The macro is in your main.cpp? Or one QObject object?

          If it is written entirely in main.cpp and is not divided into three files

          Q_OBJECT based classes need to be interpreted by MOC (Meta-Object-compiler). You can't moc your main function, if that is what you are asking.

          Is this a rule for Q_OBJECT?

          Have a look at the QObject documentation... it's the basis of the Qt Framework

          • https://doc.qt.io/qt-6/qobject.html#details
            • https://doc.qt.io/qt-6/qobject.html#Q_OBJECT

          Here are some "rules" and how it works:

          • https://doc.qt.io/qt-6/metaobjects.html
          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by jeremy_k
          #4

          @Pl45m4 said in About Q_OBJECT question:

          Here are some "rules" and how it works:

          • https://doc.qt.io/qt-6/metaobjects.html

          I suspect that OP is asking about using moc output in a single source file executable. The link above hints at a #include method, but doesn't provide an example. This technique is used in the autotests, but I don't know if I've ever seen natural language documentation. For instance, https://code.qt.io/cgit/qt/qtbase.git/tree/tests/auto/corelib/kernel/qobject/tst_qobject.cpp?h=6.7#n8838

          Here's an example usage, that should work with qmake or cmake and the appropriate automoc syntax.

          example.cpp:

          #include <QObject>
          
          class C : public QObject
          {
              Q_OBJECT
          };
          
          #include "example.moc"
          

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          2

          • Login

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