Slot executions problems in a new thread
-
Hi all,
I got a strange problem. You can see the following code.I have an object as this:
@
GestoreComunicazioneBase::GestoreComunicazioneBase() :
QObject(0)
{
...
...
m_thread = new QThread;
this->moveToThread(m_thread);
m_thread->start();
...
...
}
@and another object that Inherit GestoreComunicazioneBase :
@
GestoreComunicazioneEmh::GestoreComunicazioneEmh() :
{
QTimer::singleShot(10000, this, SLOT(leggiElencoObis()));
}
@where leggiElencoObis() is a slot of GestoreComunicazioneEmh.
When executing I get the following error message:
@
Object::connect: No such slot GestoreComunicazioneBase::leggiElencoObis() in ...
@so it seems it's looking for GestoreComunicazioneBase::leggiElencoObis() while the slot is GestoreComunicazioneEmh::leggiElencoObis() .
-
Do you have a "Q_OBJECT":http://developer.qt.nokia.com/doc/qt-4.8/qobject.html#Q_OBJECT macro also in GestoreComunicazioneEmh class definition?
-
Are you missing the Q_OBJECT macro?
-
Now I have:
@
class GestoreComunicazioneEmh : public GestoreComunicazioneBase
{
Q_OBJECT
public:
GestoreComunicazioneEmh()
...
...
@But with Q_OBJECT the compilation fails:
@
Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Debug/../satellite/gestorecomunicazioneemh.cpp:10: undefined reference to `vtable for GestoreComunicazioneEmh'
@I think it's should be a very stupid problem but I can't find it...
-
So is it solved? Because it seems that you haven't added the QObject as base class of GestoreComunicazioneEmh:
@
class GestoreComunicazioneEmh : public QObject, public GestoreComunicazioneBase
{
Q_OBJECT
public:
GestoreComunicazioneEmh(QObject* parent=NULL) : QObject(parent) {}
};
@ -
[quote author="favoritas37" date="1327329544"]So is it solved? Because it seems that you haven't added the QObject as base class of GestoreComunicazioneEmh:
@
class GestoreComunicazioneEmh : public QObject, public GestoreComunicazioneBase
{
Q_OBJECT
public:
GestoreComunicazioneEmh(QObject* parent=NULL) : QObject(parent) {}
};
@[/quote]This is WRONG! GestoreComunicazioneBase already inherits from QObject, so GestoreComunicazioneEmh is also a QObject subclass, albeit not a direct child class. Adding QObject to the inheritance list makes GestoreComunicazioneEmh in fact inherit from QObject twice, which is a bad, bad, bad idea.
-
Sorry Volker, i mentioned it because i haven't noticed that the base class already inherits from QObject. I wouldn't suggest to inherit twice from QObject.
-
[quote author="favoritas37" date="1327332502"]Sorry Volker, i mentioned it because i haven't noticed that the base class already inherits from QObject. I wouldn't suggest to inherit twice from QObject. [/quote]
No problem, everyone overlooks something now and then :) I just wanted to make sure that another potential trouble maker does sneak in :)