Qt-QBasicTimer can only be used with threads started with QThread原因探究

项目中遇到这样一个bug,程序关闭后,终端报warning:

QBasicTimer can only be used with threads started with QThread

查找资料后发现,报错的原因很可能是因为使用了static QObject造成的,在这篇文章中我已经提到过,我们不应该使用static的QObject,该篇文章中的引用1提到:

In general, creating QObjects before the QApplication is not supported and can lead to weird crashes on exit , depending on the platform. This means static instances of QObject are also not supported . A properly structured single or multi-threaded application should make the QApplication be the first created, and last destroyed QObject.

在项目中检查发现确实使用了一个static的QDialog,并且ui包含combobox的时候退出时会打印warning,如果没有combobox则不会。

在这个贴子中,提问者的现象和我一致,猜测的原因是QObject和QApplication的析构顺序造成的。

综上,解决方法就是不要使用static QObject,不论是否有报warning,否则可能出现各种奇怪的问题

引用:

  1. https://forum.qt.io/topic/143202/weird-connection-between-qcombobox-qbasictimer-and-static-object-initialization/2
  2. https://blog.csdn.net/mrbone11/article/details/123406432
相关推荐
梵高的向日葵�2392 小时前
OpenCV+MySQL+Qt构建智能视觉系统(msvc)
qt·opencv·mysql
Ulyanov2 小时前
《玩转QT Designer Studio:从设计到实战》 QT Designer Studio动画与动效系统深度解析
开发语言·python·qt·系统仿真·雷达电子对抗仿真
键盘会跳舞3 小时前
【Qt】分享一个笔者持续更新的项目: https://github.com/missionlove/NQUI
c++·qt·用户界面·qwidget
史迪仔01123 小时前
[QML] Qt Quick Dialogs 模块使用指南
开发语言·前端·c++·qt
咸鱼翻身小阿橙5 小时前
Qt页面小项目
开发语言·qt·计算机视觉
C++ 老炮儿的技术栈5 小时前
工业视觉检测:用 C++ 和 Snap7 库快速读写西门子 S7-1200
c语言·c++·git·qt·系统架构·visual studio·snap
Ulyanov5 小时前
《玩转QT Designer Studio:从设计到实战》 QT Designer Studio状态机深度应用:智能待办事项管理系统
开发语言·python·qt·gui·雷达电子对抗系统仿真
MinterFusion5 小时前
如何使用Qt5在窗口中显示矩形(v0.1.3)(上)
开发语言·qt·编程·明德融创·窗口中绘制矩形
笑春风oO5 小时前
使用国内镜像源加速Qt“更新/安装”的方法【Ubuntu篇】
开发语言·qt
sycmancia5 小时前
Qt——缓冲区操作与目录操作
开发语言·qt