Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Undefined reference to 'QGraphicsScene::QGraphicsScene(QObject*)'

 

Link error.

 

 

 

 

 

Full error message

 

/MyFolder/main.cpp:9: undefined reference to 'QGraphicsScene::QGraphicsScene(QObject*)'
/MyFolder/main.cpp:5: undefined reference to 'QGraphicsScene::~QGraphicsScene()'

 

 

 

 

 

 

Cause

 

IDE: Qt Creator 1.3.1

Compiler: G++ 4.4.1

Project type: Qt4 Console Application

Selected required modules: QtCore

 

#include <QtGui/QGraphicsScene>

int main()
{
  QGraphicsScene scene;
}

 

 

 

 

 

Solution

 

As the link error indicates, QGraphicsScene is included but not added to project. The project file might look like this:

 

#-------------------------------------------------
#
# Project created by QtCreator 2010-04-30T13:50:36
#
#-------------------------------------------------

QT -= gui

TARGET = CppQtHelloWorldWindowed
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

 

If you want to work with QGraphicsScene you will need to add QtGui to your project in the select required modules dialog in the project creation wizard. One (correct or incorrect?) way to remove it is by changing the project file to:

 

#-------------------------------------------------
#
# Project created by QtCreator 2010-04-30T13:50:36
#
#-------------------------------------------------

TARGET = CppQtHelloWorldWindowed
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict