signals emitted but slot dont call
Hi,
i have a object in my UI thread and i send a pointer of this object to another thread then i emit a signal of object but connected slot don't called:
Code:
...
void checkMyEvents() [
...
emit processfinished();
...
}
void start() {
...
othread->start();
...
}
signals:
void processfinished();
private:
MyThread* otherad;
}
{
public:
void run() {
...
obj->checkMyEvents();
...
}
MyObject* obj;
}
main() {
....
MyObject obj;
QObject::connect(&obj,
SIGNAL(processfinished
()),
&anotherObj,
SLOT(showresults
());
....
}
in debug mode i can see signals emitted but slot don't call :(
whats wrong in my code?
Re: signals emitted but slot dont call
Quote:
whats wrong in my code?
Hard to say... you show very little of it. The little we can see... the "obj" at line 34 is not related to the "obj" at lines 25 and 29, and nothing indicates how the latter gets a value.
Re: signals emitted but slot dont call
Did you forget to add Q_OBJECT?
Re: signals emitted but slot dont call
no i dont forget to add Q_OBJECT,
i send this argument to MyThread in constructor of MyObject:
othread = new MyThread(this);
Re: signals emitted but slot dont call
Quote:
i send this argument to MyThread in constructor
So you have a signal emitted from constructor ? How this could possibly work, if you call "connect" after signal has been emitted...
Maybe I'm wrong. Show us more code, maybe a compilable example.
Re: signals emitted but slot dont call
no as you can see othread start in start function of MyObject
Added after 6 minutes:
Quote:
Originally Posted by
ChrisW67
the "obj" at line 34 is not related to the "obj" at lines 25 and 29, .
i send this argument of MyObject to MyThread in constructor of MyObject:
othread = new MyThread(this);
Quote:
Originally Posted by ChrisW67;
you have a signal emitted from constructor ?
no as you can see othread start in start function of MyObject
Re: signals emitted but slot dont call
Only thing I can see is that some connect is called after you create an instance of MyObject. I don't know when start() of MyObject is called. I can only guess, but if it is in the constructor, then you can have the signal "processFinished" emitted before calling "connect" on it. If only thing called in the Threads "run" method is the emit statement, then you have a perfect example of a single threaded processing.
Show us full code or we will guess like this for next 1000 posts.
Look, this is what I mean:
Code:
// not multi-threaded
#include <QThread>
#include <QDebug>
#include <QCoreApplication>
Q_OBJECT
public:
}
void run(){
qDebug
() <<
"thread in run(): " <<
QThread::currentThread();
emit signal1();
}
signals:
void signal1();
};
Q_OBJECT
public:
{
Thread * thread = new Thread(this);
connect(thread, SIGNAL(signal1()), this, SLOT(aSlot()));
thread->run();
}
public slots:
void aSlot(){
qDebug
() <<
"A SLOT: " <<
QThread::currentThread();
}
};
int main(int argc, char ** argv){
qDebug
() <<
"thread in main(): " <<
QThread::currentThread();
MyObject obj;
qDebug() << "before exec()";
return 0;
}