Seems that my emit doesn't emit the signal
Hi,
I'm making a GUI app with the wizard and wizardpages structure and I need to do some background heavy work in some cases so I’ve created the Worker class inheriting from QObject. Then, supposing I need to do some work in wp1 which is the first wizardpage, I have:
in wp1.cpp constructor:
Code:
worker = new Worker;
worker->moveToThread(thread);
connect(this, SIGNAL(mysignal()),worker, SLOT(doWork()));
in worker.cpp:
Code:
void Worker::doWork()
{
for (int i = 0; i <=200000; ++i)
{
qDebug() << i;
QTimer::singleShot(1000,
&loop,
SLOT(quit
()));
// this should wait 1 sec like a sleep(1) loop.exec();
}
}
in wp1.cpp I overwrite keypressed to emit the signal:
Code:
void WP1
::keyPressEvent(QKeyEvent *event
) // definition {
switch(event->key())
{
case Qt::Key_1:
qDebug() <<" before";
emit(mysignal());
qDebug() << "after";
break;
}
}
My problem is that it prints ‘before’ and ‘after’ but seems that the signal is not emited so it never gets to the function worker::doWork()… Any idea of why?
(I put the emit in keypressed just to control when I emit it to test if worker functions as I expect)
Thank you!
Re: Seems that my emit doesn't emit the signal
Did you start the thread? Did you run its event loop?
Re: Seems that my emit doesn't emit the signal
ohhh shit... yes that was... forgot to thread.start();
thank you!