[英]Use multithread in c++ and qml
main.cpp
int main(int argc, char* argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc,argv);
QQmlApplicationEngine engine;
BlueToothdevice d;
engine.rootContext()->setContextProperty("device", &d);
qDebug()<<"main thread:"<< QThread::currentThreadId();
engine.load(QUrl(QStringLiteral("qrc:/assets/main.qml")));
return app.exec();
}
藍牙設備
class BlueToothdevice : public QObject { balabalabala }
藍牙設備.cpp
balabalabala
main.qml
...
Text {
id: bloodglucoseText2
text: device.bdsugar
font.pixelSize: 6 * dpi
}
...
如何將main.cpp中定義的對象“ d”移動到另一個線程? 我仍然想使用對象“ d”而不進行更改。
在Qt類中定義屬性和可調用的方法。
// Define the property bdsugar, accessible from Qml
Q_PROPERTY(bdsugar READ getBdSugar WRITE setBdSugar NOTIFY on BdSugarChanged)
// Define the method bdsugar, callable from Qml
Q_INVOKABLE QString bdsugar( return my_bdsugar; ) const;
但是沒有必要將對象d移到另一個線程(或者我不明白這個問題)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.