I have a problem with Qt multithread. I have a class that i want as a thread
//protdata.cpp
class ProtData : public QObject
{
Q_OBJECT
private:
QList<ProtDataInputHandler *> _inputs;
public:
ProtData();
void addInput();
....
};
void ProtData::addInput(QIODevice *input, bool network_order)
{
_inputs.append(new ProtDataInputHandler());
}
I have another class display.cpp where i instantiate the protdata object as a thread using moveToThread();
//display.cpp
...
QThread* newThread = new QThread();
_protdata->moveToThread(newThread);
newThread->start();
...
At some point, in display.cpp:
//display.cpp
....
_protdata->addInput();
When i execute the addInput method, i get the following error:
QObject: Cannot create children for a parent that is in a different thread. (Parent is ProtData(0x19bba50), parent's thread is QThread(0x19b3c18), current thread is QThread(0x1f08930)
What get wrong? I must move also the ProtDataInputHandler class into the newThread? How?
Thanks