Q_Object for specialization class
-
This limitation is mentioned in the moc documentation.
https://doc.qt.io/qt-6/moc.html#limitations
moc does not handle all of C++. The main problem is that class templates cannot have the Q_OBJECT macro. Here is an example:
class SomeTemplate<int> : public QFrame { Q_OBJECT ... signals: void mySignal(int); };
-
This limitation is mentioned in the moc documentation.
https://doc.qt.io/qt-6/moc.html#limitations
moc does not handle all of C++. The main problem is that class templates cannot have the Q_OBJECT macro. Here is an example:
class SomeTemplate<int> : public QFrame { Q_OBJECT ... signals: void mySignal(int); };
@jeremy_k Any alternative solution?
More detailed code like thisenum MagagerType { Interface, }; class Document { template<MagagerType T> friend class Manager; }; template <MagagerType T> class Manager { }; template<> class Manager<MagagerType::Interface> : public QObject { Q_OBJECT };
-
@jeremy_k Any alternative solution?
More detailed code like thisenum MagagerType { Interface, }; class Document { template<MagagerType T> friend class Manager; }; template <MagagerType T> class Manager { }; template<> class Manager<MagagerType::Interface> : public QObject { Q_OBJECT };
@Hu-Junhao What are you trying to achieve with this arrangement?
-
@Hu-Junhao What are you trying to achieve with this arrangement?
-
@ChrisW67 As the former code shows, I have a Document class, and serveral Manager classes, all Manager classes is friend class of Document. What I have tried to achieve is to make as few changes as possible to the Document class。
And why do you need a Q_OBJECT macro then? As already said it does not work with templates (and will not).
-
And why do you need a Q_OBJECT macro then? As already said it does not work with templates (and will not).
@Christian-Ehrlicher I need signals and slots, maybe there is another solution for me not to write friend declaration every time?
-
@Christian-Ehrlicher I need signals and slots, maybe there is another solution for me not to write friend declaration every time?
@Hu-Junhao said in Q_Object for specialization class:
I need signals and slots
Then use the new signal/slot syntax.
-
@Hu-Junhao said in Q_Object for specialization class:
I need signals and slots
Then use the new signal/slot syntax.
@Christian-Ehrlicher You mean inherits QObject but without macro Q_OBJECT maco? Compile error on
Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value, "No Q_OBJECT in the class with the signal");
-