Reputation: 2175
I wrote a simple program which emits signal inside run function of a QThread inherited class and in another class which inherits QObject wrote a slot to catch the signal, but when I compile the code I get the following errors:
symbols(s) not found for architecture x86_64 collect2: ld returned 1 exit status
and here is my code :
class visionThread : public QThread
{
public:
visionThread();
void run();
signals:
void newVisionPacket();
};
visionThread::visionThread():QThread(){
}
void visionThread::run()
{
for(int i = 0 ; i<10 ; i++)
{
emit newVisionPacket();
usleep(1000);
}
}
class dummyClass: public QObject{
public:
dummyClass(){
}
void doConnect(visionThread* v){
connect(v , SIGNAL(newVisionPacket()) , this , SLOT(mySlot()));
}
public slots:
void mySlot(){
usleep(2000);
qDebug() << "HI" << endl;
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
visionThread *vision;
vision = new visionThread();
dummyClass *dummyObject = new dummyClass();
dummyObject->doConnect(vision);
vision->start(QThread::NormalPriority);
return a.exec();
}
I'm so confused, and I would deeply appreciate any solutions.
Upvotes: 3
Views: 1347
Reputation: 32635
You have not placed Q_OBJECT macro in your classes.They should be like:
class visionThread : public QThread
{
Q_OBJECT
public:
visionThread();
void run();
signals:
void newVisionPacket();
};
And
class dummyClass: public QObject{
Q_OBJECT
public:
dummyClass(){
}
void doConnect(visionThread* v){
connect(v , SIGNAL(newVisionPacket()) , this , SLOT(mySlot()));
}
public slots:
void mySlot(){
usleep(2000);
qDebug() << "HI" << endl;
}
};
After adding the Q_OBJECT macro Clean the project, run qmake and rebuild it.
Upvotes: 4