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. help with https://doc.qt.io/qt-5/qthread.html
Forum Updated to NodeBB v4.3 + New Features

help with https://doc.qt.io/qt-5/qthread.html

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 598 Views 1 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.
  • jsulmJ jsulm

    @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

    controlsThread = new CNC::CControls(this);

    You are passing CThreadController* to the constructor, so what do you expect if CControls does not have such a constructor?

    "what is in WorkerThread constructor and what does it inherit from?" - how should we know? You did not show the code for WorkerThread...

    M Offline
    M Offline
    micha_eleric
    wrote on last edited by
    #3

    @jsulm https://doc.qt.io/qt-5/qthread.html

    1 Reply Last reply
    0
    • jsulmJ jsulm

      @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

      controlsThread = new CNC::CControls(this);

      You are passing CThreadController* to the constructor, so what do you expect if CControls does not have such a constructor?

      "what is in WorkerThread constructor and what does it inherit from?" - how should we know? You did not show the code for WorkerThread...

      M Offline
      M Offline
      micha_eleric
      wrote on last edited by
      #4

      @jsulm " - how should we know? You did not show the code for WorkerThread.." that is the question about https://forum.qt.io/topic/113070/qt-code-of-conduct

      i keep looking at webpage, trying to figure out the answer.

      jsulmJ 1 Reply Last reply
      0
      • M micha_eleric

        @jsulm " - how should we know? You did not show the code for WorkerThread.." that is the question about https://forum.qt.io/topic/113070/qt-code-of-conduct

        i keep looking at webpage, trying to figure out the answer.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #5

        @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

        that is the question about https://forum.qt.io/topic/113070/qt-code-of-conduct

        Not sure what you mean.
        I know the path to QThread documentation. I already gave you the answer to your question: there is no such constructor CNC::CControls::CControls(CThreadController*)! Please take a look at the code YOU posted:

        namespace CNC
        {
            class CControls : public QThread
            {
                Q_OBJECT
            public:
                //CControls();
        
                void run() override;
            };
        }
        

        What constructor does this class have and what constructor are you trying to call?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M micha_eleric
          void MyObject::startWorkInAThread()
          {
              WorkerThread *workerThread = new WorkerThread(this);
              connect(workerThread, &WorkerThread::resultReady, this, &MyObject::handleResults);
              connect(workerThread, &WorkerThread::finished, workerThread, &QObject::deleteLater);
              workerThread->start();
          }
          

          o have tried : QThread() and :QObject

          CThreadController.h file

          #include "CControls.h"
          #include <QObject>
          #include <QThread>
          #include <iostream>
          
          class CThreadController : public QObject
          {
              Q_OBJECT
              CNC::CControls *controlsThread;
          public:
              // constructor
              CThreadController();
              // destructor
              ~CThreadController();
          
              //
              void startThreads();
          };
          
          

          CThreadController.cpp file

          #include "CThreadController.h"
          #include "CControls.h"
          
          CThreadController::CThreadController() : QThread()
          {
          }
          
          CThreadController::~CThreadController()
          {
              controlsThread->quit();
              controlsThread->wait();
          }
          
          void CThreadController::startThreads()
          {
              std::cout << "startThreads() begin\n" << std::flush;
          
              controlsThread = new CNC::CControls(this);
              connect(controlsThread, &QThread::finished, controlsThread, &QObject::deleteLater);
              controlsThread->start();
          
              std::cout << "startThreads() end\n" << std::flush;
          }
          

          CControls.h file

          #include <QObject>
          #include <QThread>
          
          namespace CNC
          {
              class CControls : public QThread
              {
                  Q_OBJECT
              public:
                  //CControls();
          
                  void run() override;
              };
          }
          
          

          this is error i get when CThreadController inherits from QThread or QObject

          error: no matching function for call to ‘CNC::CControls::CControls(CThreadController*)’
             18 |     controlsThread = new CNC::CControl
          

          i commented out constructor, so it should default to inherited constructor

          what is in WorkerThread constructor and what does it inherit from?

          WorkerThread *workerThread = new WorkerThread(this);
          
          JKSHJ Online
          JKSHJ Online
          JKSH
          Moderators
          wrote on last edited by
          #6

          @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

          i commented out constructor, so it should default to inherited constructor

          No, constructors are not inherited like that. You must implement the relevant constructor.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          3
          • M Offline
            M Offline
            micha_eleric
            wrote on last edited by
            #7
            void MyObject::startWorkInAThread()
            {
                WorkerThread *workerThread = new WorkerThread(this);
                connect(workerThread, &WorkerThread::resultReady, this, &MyObject::handleResults);
                connect(workerThread, &WorkerThread::finished, workerThread, &QObject::deleteLater);
                workerThread->start();
            }
            

            what is the WorkerThread constructor suppose to do?
            this is not my code, so i can not show what WorkerThread constructor does.
            can someone tell me what WorkerThread constructor from https://doc.qt.io/qt-6/qthread.html is suppose to do?

            JonBJ 1 Reply Last reply
            0
            • M micha_eleric
              void MyObject::startWorkInAThread()
              {
                  WorkerThread *workerThread = new WorkerThread(this);
                  connect(workerThread, &WorkerThread::resultReady, this, &MyObject::handleResults);
                  connect(workerThread, &WorkerThread::finished, workerThread, &QObject::deleteLater);
                  workerThread->start();
              }
              

              what is the WorkerThread constructor suppose to do?
              this is not my code, so i can not show what WorkerThread constructor does.
              can someone tell me what WorkerThread constructor from https://doc.qt.io/qt-6/qthread.html is suppose to do?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #8

              @micha_eleric
              The constructor creates a QThread with MyObject instance as its parent. It is explained in that example, not sure what you are wanting to ask.

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @micha_eleric
                The constructor creates a QThread with MyObject instance as its parent. It is explained in that example, not sure what you are wanting to ask.

                M Offline
                M Offline
                micha_eleric
                wrote on last edited by
                #9

                @JonB

                class WorkerThread : public QThread
                {
                    Q_OBJECT
                    void run() override {
                        QString result;
                        /* ... here is the expensive or blocking operation ... */
                        emit resultReady(result);
                    }
                signals:
                    void resultReady(const QString &s);
                };
                    
                

                no constructor stated on https://doc.qt.io/qt-6/qthread.html

                void MyObject::startWorkInAThread()
                {
                    WorkerThread *workerThread = new WorkerThread(this);
                }
                

                results in

                485: error: no matching function for call to ‘WorkerThread(MyObject*)’
                
                JonBJ 1 Reply Last reply
                0
                • M micha_eleric

                  @JonB

                  class WorkerThread : public QThread
                  {
                      Q_OBJECT
                      void run() override {
                          QString result;
                          /* ... here is the expensive or blocking operation ... */
                          emit resultReady(result);
                      }
                  signals:
                      void resultReady(const QString &s);
                  };
                      
                  

                  no constructor stated on https://doc.qt.io/qt-6/qthread.html

                  void MyObject::startWorkInAThread()
                  {
                      WorkerThread *workerThread = new WorkerThread(this);
                  }
                  

                  results in

                  485: error: no matching function for call to ‘WorkerThread(MyObject*)’
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #10

                  @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

                  no constructor stated on https://doc.qt.io/qt-6/qthread.html

                  ?
                  The base constructor is QThread::QThread(QObject *parent = nullptr). So what is the definition of class MyObject? Or, perhaps guessing from the error message, have you declared the constructor for WorkerThread? I'm not sure you have. @JKSH answered earlier

                  i commented out constructor, so it should default to inherited constructor

                  No, constructors are not inherited like that. You must implement the relevant constructor.

                  M 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

                    no constructor stated on https://doc.qt.io/qt-6/qthread.html

                    ?
                    The base constructor is QThread::QThread(QObject *parent = nullptr). So what is the definition of class MyObject? Or, perhaps guessing from the error message, have you declared the constructor for WorkerThread? I'm not sure you have. @JKSH answered earlier

                    i commented out constructor, so it should default to inherited constructor

                    No, constructors are not inherited like that. You must implement the relevant constructor.

                    M Offline
                    M Offline
                    micha_eleric
                    wrote on last edited by
                    #11

                    @JonB said in help with https://doc.qt.io/qt-5/qthread.html:

                    @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

                    no constructor stated on https://doc.qt.io/qt-6/qthread.html

                    ?
                    The base constructor is QThread::QThread(QObject *parent = nullptr). So what is the definition of class MyObject? Or, perhaps guessing from the error message, have you declared the constructor for WorkerThread? I'm not sure you have. @JKSH answered earlier

                    i commented out constructor, so it should default to inherited constructor

                    No, constructors are not inherited like that. You must implement the relevant constructor.

                    i have no clue what the constructor is suppose to be for WorkerThread, sence the webpage does not say, and i keep asking what it is suppose to be

                    JonBJ 1 Reply Last reply
                    0
                    • M micha_eleric

                      @JonB said in help with https://doc.qt.io/qt-5/qthread.html:

                      @micha_eleric said in help with https://doc.qt.io/qt-5/qthread.html:

                      no constructor stated on https://doc.qt.io/qt-6/qthread.html

                      ?
                      The base constructor is QThread::QThread(QObject *parent = nullptr). So what is the definition of class MyObject? Or, perhaps guessing from the error message, have you declared the constructor for WorkerThread? I'm not sure you have. @JKSH answered earlier

                      i commented out constructor, so it should default to inherited constructor

                      No, constructors are not inherited like that. You must implement the relevant constructor.

                      i have no clue what the constructor is suppose to be for WorkerThread, sence the webpage does not say, and i keep asking what it is suppose to be

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #12

                      @micha_eleric
                      You should do, because it is the same as the base class one:

                      public: 
                          explicit WorkerThread(QObject *parent = 0) :
                              QThread(parent)
                          {
                          }
                      
                      M 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @micha_eleric
                        You should do, because it is the same as the base class one:

                        public: 
                            explicit WorkerThread(QObject *parent = 0) :
                                QThread(parent)
                            {
                            }
                        
                        M Offline
                        M Offline
                        micha_eleric
                        wrote on last edited by
                        #13

                        @JonB ty. i was wandering about that based on other pages, but not sure

                        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