3

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 = 
László Papp
  • 51,870
  • 39
  • 111
  • 135
uniquenamehere
  • 1,869
  • 3
  • 31
  • 60
  • Please paste more of the error message. Which file is trying to include qcustomplot.h? – László Papp Jan 12 '14 at 08:20
  • i am new to stackoverflow without enough 'reputation' somehow that i can not add a comment to @Shea Belsky. i followed the instruction of his and solve the problem. i think he may forgot one step in his answer. Here is my step by step according to his: Step 1: Open the ***.ui file which contains the qcustomplot item. Step 2: Right click the qcustomplot item AND CLICK 'PROMOTED WIDGETS' ! Step 3: Double click the path of QCustomPlot, then change it to QCustomPlot/qcustomplot.cpp from ../../customplot. just like this: [enter image description here](https://i.stack.imgur.com/yY9Am.png) Finally, t – NoSuchFile Jul 01 '17 at 10:59

2 Answers2

2

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
0

I met the same problem and have solved it.

It was caused by the path of qcustomplot object in xxx.ui.

Step 1: Open the ***.ui file which contains the qcustomplot item.

Step 2: Right click the qcustomplot item

Step 3: Double click the path of QCustomPlot, then change it to QCustomPlot/qcustomplot.cpp from ../../customplot.

Finally, the header of ui_***.h can auto include QCustomPlot/qcustomplot.cpp, instead of ../../qcustomplot.h.

My native language isn't English. If you find grammar mistake in my reply, please inform me. Let me correct it.

Shea Hunter Belsky
  • 2,815
  • 3
  • 22
  • 31