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"を使用したい。
これを試す[link](https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/) – JLev
ありがとう、私はクラスBlueToothdeviceで多くの機能を持っているので、 "device.bdsugar"のようにqmlでオブジェクトdを使用しています。あなたが与えたリンクはこの問題を解決できません – user8551063