Important: Please read the Qt Code of Conduct -

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.

    /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()));

    Thanks for help

  • @nuke
    the error message have said that QThread::exec() is a protected member of QThread

    if you want to start a thread use QThread::start

    read the documentation for some example

  • @nuke
    threadBlink = new QThread();
    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.

  • Lifetime Qt Champion

    Did you read example from Doc?
    Do you have
    Worker *worker = new Worker;

  • 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

Log in to reply