如何从qml启动Qthread? [英] How Start a Qthread from qml?

查看:90
本文介绍了如何从qml启动Qthread?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要立即开始并从Qml File中停止QThread扩展类.有什么解决办法吗?这是我的课:

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 : public QThread
{
    Q_OBJECT
public:
    CircularList<unsigned char> buffer_[2];

signals:
    void dataReady(short *value,int len,unsigned short sample);

protected:
    void run();
};

推荐答案

如果您具有如下的SerialManager:

if you have SerialManager like this:

class SerialManager : public QThread
{
    Q_OBJECT
public:
    CircularList<unsigned char> buffer_[2];

signals:
    void dataReady(short *value,int len,unsigned short sample);

protected:
    void run();
};

在main.cpp中添加以下代码:

in main.cpp add bellow code:

qmlRegisterType<SerialManager>("Device",1,0,"Serial");

然后在您的qml中执行以下操作:

then in your qml do this:

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

    }

这篇关于如何从qml启动Qthread?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆