threads and created objects
-
@SGaist said in threads and created objects:
I fixed the typo of parented (damn autocorrect...
Well, while you're at it..."QTcoSocket?"
@mzimmers said in threads and created objects:
@SGaist said in threads and created objects:
I fixed the typo of parented (damn autocorrect...
Well, while you're at it..."QTcoSocket?"
Argle........ Done
-
If you want the
QObjects to to be moved alongside with their parent to another thread, then you must pass them the parent. No parent, no way Qt to know whether the object's supposed to be moved.@kshegunov I don't know how to do that in this case. If my SerialPort object is defined:
class SerialPort : public QObject { Q_OBJECT public: explicit SerialPort(Worker *parent = nullptr); ... SerialPort::SerialPort(Worker *parent) : QObject(parent)Then how do I declare an instance of SerialPort in my worker object? If I do it like this:
SerialPort m_serial;Then it doesn't seem to get moved.
-
The usual: pointer and allocate it in the constructor with a parent.
-
@SGaist OK, thanks. I had (incorrectly) inferred from kshegunov's post that it somehow could be done as an ordinary member variable.
-
@mzimmers No the inference is correct. This shall work, shan't it?
class Worker : public QObject { Q_OBJECT public: Worker(); private: SerialPort m_serial; }; Worker::Worker() : m_serial(this) { }@kshegunov well...yes it does. I was missing the " : m_serial(this)" clause. Thanks!