error: type 'QObject' is not a direct base of 'MyThread'
-
'QObject' is not a direct base of 'MyThread'
And what do you don't understand here? The message explicitly tells you what's wrong. MyThread doesn't directly derive from QObject...
-
@suslucoder
Show your declaration ofclass MyThread
inmythread.h
. -
#define MYTHREAD_H #include <QtCore> #include <QMainWindow> #include <QObject> #include <QWidget> #include <QQueue> #include <QMutex> class MyThread: public QThread { Q_OBJECT public: MyThread(QObject* parent =nullptr); ~MyThread(); signals: void writingDone(); //signal for main thread public slots: void writeData(); // this slot ask the thread to write data void run(); private: QQueue<double> queue; }; #endif // MYTHREAD_H
-
@suslucoder said in error: type 'QObject' is not a direct base of 'MyThread':
class MyThread: public QThread
Exactly what the error message told you...
No need to derive from QThread here at all btw. -
@Christian-Ehrlicher Im trying to do subclass QObject. I can read also the error. Obviously I'm doing something wrong. Do you think is it the true way you make me realize my mistake?
-
@suslucoder said in error: type 'QObject' is not a direct base of 'MyThread':
Im trying to do subclass QObject
But you don't:
class MyThread: public QThread
-
@suslucoder
Can I ask you one thing: are you trying to use threads because this is an assignment/exam/educational? Do you really have any need for using threads, for whatever you are trying to achieve? Threads are one of the hardest things to get right. So many beginners on this forum start out trying to use threads when there is no need to do so, and run into problems, it could be a bad idea and not at all needed. If I were learning Qt they are the last thing I would want to start out on. Unless you have a good reason for really wanting to use them. -
@suslucoder said in error: type 'QObject' is not a direct base of 'MyThread':
I just want to learn all subjects quickly
Then I would start with the basics and not with advanced topics like threads.
-
@Christian-Ehrlicher thank you, i understand my mistake and solve it.