QT Creator fails to parse a very easy project

Aleksei Petrenko picture Aleksei Petrenko · Jan 17, 2013 · Viewed 8.1k times · Source

I created a very simple project in QT creator, *.pro file is just following:

HEADERS += inc\1.h
SOURCES += src\1.cpp

Here is the source code:

// 1.h
const int C = 1;

// 1.cpp
#include "1.h"

int main() {
    return C;
}

QT Creator successfully opens this "project", but cannot parse it. F2 does not work for C constant, 1.h header cannot be found.

Please look at the screenshot which describes the problem:

Screenshot showing the project structure

The most strange part is that exactly the same thing seems to work on my other machine with similar QT SDK 5.0 installation! Could you please advise where am I wrong?

Answer

Tim Meyer picture Tim Meyer · Jan 17, 2013

HEADERS is supposed to list the header files of your own project, just like SOURCES lists the source files.

If you want to include external header files, you should add their folders to INCLUDEPATH instead:

INCLUDEPATH += inc

The following .pro file works perfectly in Qt Creator 2.5.0, Qt 4.6.1:

QT       += core
QT       -= gui

TARGET = test
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += \
    src/1.cpp

INCLUDEPATH += inc

Try that exact .pro file, give it 3 seconds to parse and tell me if it worked.