start from here

WOVLEX.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This error message occurs when you attempt to start a QBasicTimer object from a different thread than the one it was created in. QBasicTimer is designed to be used with the event loop of the thread it was created in, and it is not thread-safe. To fix this error, you need to ensure that the QBasicTimer object is started from the same thread it was created in. You can do this by using signals and slots to communicate between threads, or by using a different type of timer that is designed to be used across multiple threads, such as QTimer. Here is an example of using signals and slots to start a QBasicTimer from another thread: ``` // In the main thread: QBasicTimer timer; connect(&workerThread, &QThread::started, &timer, &QBasicTimer::start); // In the worker thread: void WorkerThread::run() { // Do some work... emit started(); // Do some more work... } ``` In this example, the QBasicTimer object is created in the main thread and connected to the started signal of the worker thread. When the worker thread starts, it emits the started signal, which triggers the start method of the QBasicTimer object in the main thread. Alternatively, you can use a QTimer object, which is designed to be used across multiple threads: ``` // In the main thread: QTimer timer; timer.moveToThread(&workerThread); connect(&workerThread, &QThread::started, &timer, &QTimer::start); // In the worker thread: void WorkerThread::run() { // Do some work... // QTimer::start will now be called in the worker thread } ``` In this example, the QTimer object is created in the main thread and moved to the worker thread using the moveToThread method. The started signal of the worker thread is connected to the start method of the QTimer object, which can now be safely called from the worker thread.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值