0
votes

i have develop a class MyDevice which is a C to C++ wrapper. I would to create thread in which all method from the class will be run.

I have define the class as below:

class DeviceMngr
{
    Q_OBJECT
    QThread DeviceThread;

public:
    DeviceMngr();
    ~DeviceMngr();
    void OpenDevice();

In the main.cpp, I have done :

DeviceMngr *MyDevice = new DeviceMngr;

What I want after is to move MyDevice to a Thread I thought using :

MyDevice->moveToThread(&DeviceThread);

After, I plan to create signal/slot to connect the main thread to the DeviceMngr one.

What is strange is that the moveToThread do not appear as autocompletion. The build do not recognize the movetothread.

Did I miss something in the Qthread ?

1

1 Answers

1
votes

It seems your DeviceMngr class is not derived from QObject. moveToThread is instance method of QObject class.

So, to be able to use moveToThread, please derive your class from QObject first. This link might help.