help with https://doc.qt.io/qt-5/qthread.html
-
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);
-
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);
@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...
-
@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...
-
@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...
@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.
-
@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.
@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?
-
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);
@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.
-
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? -
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?@micha_eleric
The constructor creates aQThread
withMyObject
instance as its parent. It is explained in that example, not sure what you are wanting to ask. -
@micha_eleric
The constructor creates aQThread
withMyObject
instance as its parent. It is explained in that example, not sure what you are wanting to ask.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*)’
-
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*)’
@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 ofclass MyObject
? Or, perhaps guessing from the error message, have you declared the constructor forWorkerThread
? I'm not sure you have. @JKSH answered earlieri commented out constructor, so it should default to inherited constructor
No, constructors are not inherited like that. You must implement the relevant constructor.
-
@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 ofclass MyObject
? Or, perhaps guessing from the error message, have you declared the constructor forWorkerThread
? I'm not sure you have. @JKSH answered earlieri commented out constructor, so it should default to inherited constructor
No, constructors are not inherited like that. You must implement the relevant constructor.
@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 ofclass MyObject
? Or, perhaps guessing from the error message, have you declared the constructor forWorkerThread
? I'm not sure you have. @JKSH answered earlieri 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
-
@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 ofclass MyObject
? Or, perhaps guessing from the error message, have you declared the constructor forWorkerThread
? I'm not sure you have. @JKSH answered earlieri 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
@micha_eleric
You should do, because it is the same as the base class one:public: explicit WorkerThread(QObject *parent = 0) : QThread(parent) { }
-
@micha_eleric
You should do, because it is the same as the base class one:public: explicit WorkerThread(QObject *parent = 0) : QThread(parent) { }
@JonB ty. i was wandering about that based on other pages, but not sure