Qt - QWidget:当没有使用GUI时,无法创建QWidget [英] Qt - QWidget: Cannot create a QWidget when no GUI is being used

查看:1410
本文介绍了Qt - QWidget:当没有使用GUI时,无法创建QWidget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行一个简单的 Qt 程序,当这样做,我得到一个控制台窗口提到: QWidget:无法创建没有使用GUI时的QWidget ,第二行此应用程序请求运行时终止..... c $ c> .exe 文件因此停止工作。

I'm trying to run a simple Qt program, and when doing so, I get a console window mentioning: QWidget: Cannot create a QWidget when no GUI is being used, and the second line This application has requested the Runtime to terminate....., and the .exe file thus stops working.

我的 .pro 档案如下:

#-------------------------------------------------
#
# Project created by QtCreator 2011-04-02T07:38:50
#
#-------------------------------------------------

QT       += core

QT       += gui

TARGET = Hello
CONFIG += console
CONFIG += qt
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

有任何想法吗?

谢谢。

推荐答案

问题不在这个 .pro ;它很可能在 main.cpp 中。 Qt要求您在创建任何QWidget子类(以及某些其他类,如QPixmap之前)创建一个QApplication。您的 main 函数应以以下行开头:

The problem is not with this .pro; it is most likely in main.cpp. Qt requires you to create a QApplication before creating any QWidget subclasses (as well as certain other classes, such as QPixmap). Your main function should begin with the line:

QApplication app(argc, argv);

,可能会以如下结尾:

return app.exec();

在这些调用之间,您应该创建并显示您的主窗口。

In between these calls, you should create and show your main window.

这篇关于Qt - QWidget:当没有使用GUI时,无法创建QWidget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆