Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = 
like image 812
uniquenamehere Avatar asked Mar 09 '26 21:03

uniquenamehere


1 Answers

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.

like image 122
lpapp Avatar answered Mar 12 '26 13:03

lpapp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!