Solved Problems with QThread
-
Hi
i am trying to use QThread. I use simple code in constructor of my class.
metod blink is declared as public slot in header file.Error:
/opt/qt5pi/include/QtCore/qthread.h:120: error: ‘int QThread::exec()’ is protected
int exec();QThread *threadBlink = new QThread(this); connect(this->threadBlink, SIGNAL(started()), this, SLOT(blink())); threadBlink->exec();
Thanks for help
-
@nuke
the error message have said thatQThread::exec()
is a protected member ofQThread
if you want to start a thread use
QThread::start
read the documentation for some example
-
@nuke
threadBlink = new QThread();
threadBlink->start();
connect(threadBlink, SIGNAL(started()), this, SLOT(blink()));It would be good if threadBlink = new QThread (); Announced constructor.
Try it and if any problem write here.
-
Thanks for help it really works.
But i found another problem when strat the QThread the program does not work as i want it waits until the thread finishes. In method blink is infinite loop for blinking LED i thought it should work separatly from the main program. -
@nuke
Did you read example from Doc?
Do you have
Worker *worker = new Worker;
worker->moveToThread(&workerThread); -
Thanks a lot for help. No i dont use worker i wanted to implement just infinite loop in separate thread not to implement whole class worker. At the end i used pthread and it works just fine.
Thanks for help