Alex Rivera | Logout

Qt - QWidget: Cannot create a QWidget when no GUI is being used

Asked 2011-04-02T07:02:57.720
13

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.

My .pro file looks as follows:

#-------------------------------------------------
#
# 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

Any ideas on that?

Thanks.

Edit
Report

2 Answers

18

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);

and will probably end with a line like:

return app.exec();

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

answered 2011-04-02T07:12:22.367
3

I think I found where the issue is.

Since I'm using Qt Creator, and when creating a new project, I was choosing Qt Console Application instead of Qt Gui Application.

answered 2011-04-02T07:28:34.737

Your Answer