How Start a Qthread from qml?

前端 未结 3 675
误落风尘
误落风尘 2021-01-21 18:26

I need to Start immediately and stop then a QThread extended class from Qml File. Is there any solution for that? here is my class :

class SerialManager : publi         


        
3条回答
  •  臣服心动
    2021-01-21 19:01

    if you have SerialManager like this:

    class SerialManager : public QThread
    {
        Q_OBJECT
    public:
        CircularList buffer_[2];
    
    signals:
        void dataReady(short *value,int len,unsigned short sample);
    
    protected:
        void run();
    };
    

    in main.cpp add bellow code:

    qmlRegisterType("Device",1,0,"Serial");
    

    then in your qml do this:

     Component.onCompleted: {
                thread.start()
            }
     Component.onDestruction:
        {
            thread.quit()
    
        }
    

提交回复
热议问题