Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problems with QThread
Forum Updated to NodeBB v4.3 + New Features

Problems with QThread

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nuke
    wrote on 24 Mar 2017, 23:34 last edited by
    #1

    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

    F T 2 Replies Last reply 25 Mar 2017, 01:48
    0
    • N nuke
      24 Mar 2017, 23:34

      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

      F Offline
      F Offline
      Flotisable
      wrote on 25 Mar 2017, 01:48 last edited by
      #2

      @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

      1 Reply Last reply
      1
      • N nuke
        24 Mar 2017, 23:34

        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

        T Offline
        T Offline
        Taz742
        wrote on 25 Mar 2017, 07:12 last edited by
        #3

        @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.

        Do what you want.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nuke
          wrote on 25 Mar 2017, 09:58 last edited by
          #4

          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.

          M 1 Reply Last reply 25 Mar 2017, 10:09
          0
          • N nuke
            25 Mar 2017, 09:58

            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.

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 25 Mar 2017, 10:09 last edited by
            #5

            @nuke
            Did you read example from Doc?
            Do you have
            Worker *worker = new Worker;
            worker->moveToThread(&workerThread);

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nuke
              wrote on 25 Mar 2017, 10:24 last edited by
              #6

              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

              1 Reply Last reply
              0

              1/6

              24 Mar 2017, 23:34

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved