Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Cannot create a QWidget when no GUI is being used

 

Runtime error.

 

 

 

 

 

Full error message

 

 

Starting /MyFolder/mymain.cpp...
QWidget: Cannot create a QWidget when no GUI is being used
The program has unexpectedly finished.
/MyFolder/mymain exited with code 0

 

 

 

 

 

Cause

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: GUI Application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

Qt project file

 

#-------------------------------------------------
#
# Project created by QtCreator 2010-07-24T12:32:57
#
#-------------------------------------------------
QT += core gui
TARGET = CppRuntimeErrorCannotCreateAqwidgetWhenNoGuiIsBeingUsed
TEMPLATE = app
SOURCES += main.cpp

 

 

 

 

 

Source code

 

#include <QtCore/QCoreApplication>
#include <QDialog>

int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);
  QDialog d;
  d.show();
  return a.exec();
}

 

 

 

 

 

 

Solution

 

Do not use QCoreApplication, but use QApplication instead.

 

#include <QApplication>
#include <QDialog>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QDialog d;
  d.show();
  return a.exec();
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict