PDA

View Full Version : How to emit signals from QRunnable?



mlheese
29th July 2010, 19:33
How do you setup a QRunnable class so that it can emit signals?? Others on this forum say it is possible but nobody shows a good code snippet. If I try to use the following class definition, I get the compiler error:
error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CMyTestClass::metaObject(void)const " (?metaObject@CMyTestClass@@UBEPBUQMetaObject@@XZ)
1>threadtestapp.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall CMyTestClass::qt_metacast(char const *)" (?qt_metacast@CMyTestClass@@UAEPAXPBD@Z)
1>threadtestapp.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CMyTestClass::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CMyTestClass@@UAEHW4Call@QMetaObject @@HPAPAX@Z)
1>threadtestapp.obj : error LNK2019: unresolved external symbol "protected: void __thiscall CMyTestClass::fireEventNotification(class QString const &)"

My class is defined as:

class CMyTestClass : public QObject, public QRunnable
{
Q_OBJECT

public:
CMyTestClass(){}
~CMyTestClass(){}

void run(){
QString str = "sample";
emit fireEventNotification(str);
}
void Initialize(const QString &str){}

signals:
void fireEventNotification(const QString &);

};

I want to have numerous threads running that will each throw signals back to the main app about status info. The main app slot handlers don't care which thread threw the signal it just displays the str message to a listview.

ChrisW67
29th July 2010, 23:26
That is a linker error related to the moc generated code. Re-run qmake and rebuild.