QObject::connect returns false
-
@J-Hilk , clsSchdSrv.h, still a early work in progress:
class clsSchdSrv : public QTimer { Q_OBJECT public: explicit clsSchdSrv(QObject* pParent = 0); void kick(); public slots: virtual void expired() = 0; }
Sorry, should have added:
class clsTimeSync : public clsSchdSrv { public: explicit clsTimeSync(); public slots: virtual void expired(); void updateTime(int intTimeNow); }
-
@J-Hilk , clsSchdSrv.h, still a early work in progress:
class clsSchdSrv : public QTimer { Q_OBJECT public: explicit clsSchdSrv(QObject* pParent = 0); void kick(); public slots: virtual void expired() = 0; }
Sorry, should have added:
class clsTimeSync : public clsSchdSrv { public: explicit clsTimeSync(); public slots: virtual void expired(); void updateTime(int intTimeNow); }
@SPlatten said in QObject::connect returns false:
clsSchdSrv.h, still a early work in progress:
I am not sure, you can declare a
slot
as virtual.
I would change this to:class clsSchdSrv : public QTimer { Q_OBJECT public: explicit clsSchdSrv(QObject* pParent = 0); void kick(); public: virtual void onExpired() = 0; public slots: void expired() { onExpired(); } }
-
@SPlatten said in QObject::connect returns false:
public slots:
virtual void expired() = 0;But you use
SLOT(updateTime())
?Why are you showing us
clsSchdSrv
? Earlier you showedclsTimeSync
? -
@SPlatten said in QObject::connect returns false:
please see the edited post which includes the derived class, sorry.
In this header signal signature is
void updateTime(int)
and notvoid updateTime(long)
@KroMignon said in QObject::connect returns false:
In this header signal signature is void updateTime(int) and not void updateTime(long)
That's coz he has changed per earlier on.
I agree we do not know for sure what his code is, but I think he dealt with that alteration. -
@SPlatten your derived class will need the Q_OBJECT macro as well, if it defines slots/signals
-
@SPlatten said in QObject::connect returns false:
please see the edited post which includes the derived class, sorry.
In this header signal signature is
void updateTime(int)
and notvoid updateTime(long)
@KroMignon , because I changed it from long to int after earlier posts.
-
@SPlatten said in QObject::connect returns false:
@J-Hilk , why? The class it inherits already has that.
That's not how it works. Which is why I said to try putting
Q_OBJECT
in.Can you please do that and then we will discuss why if it makes any difference?
-
@SPlatten said in QObject::connect returns false:
@J-Hilk , why? The class it inherits already has that.
That's not how it works. Which is why I said to try putting
Q_OBJECT
in.Can you please do that and then we will discuss why if it makes any difference?
-
@JonB , adding Q_OBJECT to the inherit class results in the compiler error:
undefined erference to `vtable for clsTimeSync`
@SPlatten said in QObject::connect returns false:
results in the compiler error
You need to do a complete rebuild
-
@SPlatten said in QObject::connect returns false:
why? The class it inherits already has that.
Because it is a Qt recommendation (cf. https://doc.qt.io/qt-5/metaobjects.html)
The meta-object system is based on three things:
- The QObject class provides a base class for objects that can take advantage of the meta-object system.
- The Q_OBJECT macro inside the private section of the class declaration is used to enable meta-object features, such as dynamic properties, signals, and slots.
- The Meta-Object Compiler (moc) supplies each QObject subclass with the necessary code to implement meta-object features.
-
@JonB , adding Q_OBJECT to the inherit class results in the compiler error:
undefined erference to `vtable for clsTimeSync`
-
@SPlatten said in QObject::connect returns false:
results in the compiler error
You need to do a complete rebuild
-
@SPlatten said in QObject::connect returns false:
@J-Hilk , why? The class it inherits already has that.
Q_OBJECT
is a macro. You can look at what it does.I know the rule is:
-
Every class which defines signals MUST have
Q_OBJECT
in that class definition. Inheritance from parent is not what it's about. -
Normally I believe slot-only classes do not have to have
Q_OBJECT
. HOWEVER I only work with the new-styleconnect()
syntax, not available in Qt4. It may be that to useSLOT()
you do also needQ_OBJECT
in old style? When in doubt --- and certainly if I were having a problem --- I would putQ_OBJECT
into classes with slots just in case.....
-