在 c++ 和 qml 中使用多线程
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();
}
蓝牙设备.h
class BlueToothdevice : public QObject { balabalabala }
蓝牙设备.cpp
balabalabala
主.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 移动到另一个线程(或者我不明白这个问题(。
相关文章:
- 在C++中使用cURL和多线程
- 多线程双缓冲区
- 为什么我的多线程作业队列崩溃
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 试图创建一个多线程程序来查找0-100000000之间的总素数
- 为什么一个向量上的多线程操作很慢
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 全局变量 多读取器 一个写入器多线程安全?
- boost::文件系统::recursive_directory_iterator多线程安全
- 如何阻止TensorFlow的多线程
- 如何在多线程中正确使用unique_ptr进行多态性?
- 并发/多线程:是否可以以这种方式生成相同的输出?
- sigwait() 在多线程程序中不起作用
- 多线程程序中出现意外的内存泄漏
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 多线程比没有线程C++慢
- 具有 C++11 多线程的特征库
- 通过安装信号处理程序关闭多线程应用程序
- 在 c++ 和 qml 中使用多线程
- QML是否与多线程/异步调用兼容