2017-11-12 23 views
0

main.cppに使用C++でマルチスレッドとQML

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(); 
} 

BlueToothdevice.h

class BlueToothdevice : public QObject { balabalabala } 

BlueToothdevice.cpp

balabalabala 

main.qml

... 
Text { 
    id: bloodglucoseText2 
    text: device.bdsugar 
    font.pixelSize: 6 * dpi 
} 
... 

main.cppで定義されたオブジェクト "d"を別のスレッドに移動する方法はありますか?私はまだ変更せずにオブジェクト "d"を使用したい。

+0

これを試す[link](https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/) – JLev

+0

ありがとう、私はクラスBlueToothdeviceで多くの機能を持っているので、 "device.bdsugar"のようにqmlでオブジェクトdを使用しています。あなたが与えたリンクはこの問題を解決できません – user8551063

答えて

0

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を移動させる必要がない(または私は質問を理解していませんでした)。

関連する問題