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. Is this a rule for Q_OBJECT?
@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 oneQObject
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 FrameworkHere are some "rules" and how it works:
-
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?
@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".
-
@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 oneQObject
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 FrameworkHere are some "rules" and how it works:
@Pl45m4 said in About Q_OBJECT question:
Here are some "rules" and how it works:
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"