Error: QWidget: Cannot create a QWidget without QApplication

来源:互联网 发布:51单片机isp下载 编辑:程序博客网 时间:2024/04/30 12:10

自己在新建QT工程时,没有选择Qt Widgets应用,而是选择Qt 控制台程序:


(现在还不清楚这些具体各个应用程序的区别尴尬)

结果自己在建主窗口程序时,出现下面的错误(QWidget: Cannot create a QWidget without QApplication):


产生这个错误的原因是这个QWidget 是建立在QApplication 上的,(From the docs, the QApplication class manages the GUI application's control flow and main settings whilst the QCoreApplication class provides an event loop for console Qt applications),改成下面的代码就行了:


参考:

【1】 解决QWidget: Cannot create a QWidget when no GUI is being used http://blog.csdn.net/muyuyuzhong/article/details/7034301

【2】Qt - QWidget: Cannot create a QWidget when no GUI is being used http://stackoverflow.com/questions/5521752/qt-qwidget-cannot-create-a-qwidget-when-no-gui-is-being-used

0 0
原创粉丝点击