Search code examples
c++qtqmakeqtguiqcustomplot

Qt auto generated form provides wrong path to source code files


I have added qcustomplot.h/.c files to my Qt project. They are located in: "QT_PROJECT_DIR/QCustomPlot/".

Every time I use the designer in Qt Creator and build I get this error in ui_mainwindow.h:

error: ../../qcustomplot.h: No such file or directory
#include "../../qcustomplot.h"

This is of course true as it is located in: "QT_PROJECT_DIR/QCustomPlot/"

How do I change how Qt Designer auto generate this path?

If it helps, here is my .pro:

#-------------------------------------------------
#
# Project created by QtCreator 2014-01-12T00:44:44
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets widgets opengl printsupport

TARGET = Test
TEMPLATE = app

SOURCES += main.cpp\
        mainwindow.cpp \
    QCustomPlot/qcustomplot.cpp

HEADERS  += mainwindow.h \
    QCustomPlot/qcustomplot.h

FORMS    += mainwindow.ui

CONFIG += mobility
MOBILITY = 

Solution

  • Your include seems to be wrong:

    #include "../../qcustomplot.h"
    

    Since you do not add the QCustomPlot folder to your INCLUDEPATH, you would need to include the file as follows:

    #include "QCustomPlot/qcustomplot.h"
    

    Alternatively, you could change the INCLUDEPATH as follows:

    INCLUDEPATH += $$QT_PROJECT_DIR/QCustomPlot/
    

    and then you could include the header without the ugly ../../ relative reference as follows:

    #include "qcustomplot.h"
    

    It is a rule of thumb to avoid such relative include paths in the source and headers files themselves because the structure can change at any time, or may be different on a different machine, et al. It is better resolved by the buildsystem and include paths.