Qt自动生成的表单提供了源代码文件的错误路径

时间:2022-03-22 18:46:22

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

我有添加qcustomplot.h /。c文件到我的Qt项目。它们位于:“QT_PROJECT_DIR/QCustomPlot/”。

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

每次我在Qt Creator中使用设计器并构建时,在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/"

这当然是正确的,因为它位于:“QT_PROJECT_DIR/QCustomPlot/”

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

如何改变Qt设计器自动生成路径?

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 = 

2 个解决方案

#1


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:

由于您没有将QCustomPlot文件夹添加到INCLUDEPATH,因此需要将该文件包括如下内容:

#include "QCustomPlot/qcustomplot.h"

Alternatively, you could change the INCLUDEPATH as follows:

或者,您也可以将INCLUDEPATH改为:

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.

避免在源文件和头文件本身中包含这样的相对路径是一个经验法则,因为结构可以随时改变,或者在不同的机器上可能不同。

#2


0  

I met the same problem and have solved it.

我遇到了同样的问题并解决了它。

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

它是由xxx.ui中qcustomplot对象的路径引起的。

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

第一步:打开***。包含qcustomplot项的ui文件。

Step 2: Right click the qcustomplot item

步骤2:右键单击qcustomplot项

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

步骤3:双击QCustomPlot的路径,然后将其更改为QCustomPlot/ QCustomPlot。从. . / . . / customplot cpp。

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

最后是ui_***的header。h可以自动包含QCustomPlot/ QCustomPlot。cpp,而不是. . / . . / qcustomplot.h。

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

我的母语不是英语。如果你在我的回复中发现语法错误,请通知我。让我改正它。

#1


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:

由于您没有将QCustomPlot文件夹添加到INCLUDEPATH,因此需要将该文件包括如下内容:

#include "QCustomPlot/qcustomplot.h"

Alternatively, you could change the INCLUDEPATH as follows:

或者,您也可以将INCLUDEPATH改为:

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.

避免在源文件和头文件本身中包含这样的相对路径是一个经验法则,因为结构可以随时改变,或者在不同的机器上可能不同。

#2


0  

I met the same problem and have solved it.

我遇到了同样的问题并解决了它。

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

它是由xxx.ui中qcustomplot对象的路径引起的。

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

第一步:打开***。包含qcustomplot项的ui文件。

Step 2: Right click the qcustomplot item

步骤2:右键单击qcustomplot项

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

步骤3:双击QCustomPlot的路径,然后将其更改为QCustomPlot/ QCustomPlot。从. . / . . / customplot cpp。

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

最后是ui_***的header。h可以自动包含QCustomPlot/ QCustomPlot。cpp,而不是. . / . . / qcustomplot.h。

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

我的母语不是英语。如果你在我的回复中发现语法错误,请通知我。让我改正它。