my SLOT not part of QThread
Hello, I got the following problem.
Code:
{
public:
mythread();
void run();
public slots:
void processpacket();
private:
};
inside mythread::run I have this
Code:
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(processpacket()));
everything compiles and builds but when I run it I get a
Code:
Object
::connect: No such
slot QThread::processpacket().
and if I add Q_OBJECT as follows:
Code:
class mythread : public Qthread
{
Q_OBJECT
public:
mythread();
void run();
public slots:
void processpacket();
private:
};
I get the following error when compiling.:
undefined reference to 'vtable for mythread'
Any help in solving this issues is appreciated. Thanks in advanced
Re: my SLOT not part of QThread
Re-run qmake after adding Q_OBJECT macro.
Re: my SLOT not part of QThread
Thanks Jpn, that solved both problems. Now i have a problem where the SLOT code is never executed. I send packets from my client machine but it does nothing. is the code shown above incorrect?
Thanks in advanced
Re: my SLOT not part of QThread
Quote:
Originally Posted by freak
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(processpacket()));
Beware that a QThread object and all objects created in its constructor live in a thread where that QThread instance was created, while all objects created in QThread::run() live in a newly created thread.
This means that the above connection will be a queued connection and processpacket() won't be executed by the new thread. Either move those slots to some other object that you will create in QThread::run() or make that connection a direct one explicitly.
Re: my SLOT not part of QThread
Quote:
Originally Posted by freak
Now i have a problem where the SLOT code is never executed.
Do you start the event loop in that new thread (i.e. do you invoke QThread::exec() in run() )?
Re: my SLOT not part of QThread
I do call exec() inside run.
How do you make a connection explicitly?
Re: my SLOT not part of QThread
Quote:
Originally Posted by freak
How do you make a connection explicitly?
Code:
connect( tcpServer, SIGNAL( newConnection() ),
this, SLOT( processpacket() ),
Qt::DirectConnection );