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

Problems with QThread

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.5k Views
  • 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.
  • nukeN Offline
    nukeN Offline
    nuke
    wrote on 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

    FlotisableF Taz742T 2 Replies Last reply
    0
    • nukeN nuke

      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

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on 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
      • nukeN nuke

        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

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on 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
        • nukeN Offline
          nukeN Offline
          nuke
          wrote on 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.

          mrjjM 1 Reply Last reply
          0
          • nukeN nuke

            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.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            • nukeN Offline
              nukeN Offline
              nuke
              wrote on 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

              • Login

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