QtCreator:如何编译外部源文件 [英] QtCreator: How to compile external source files
问题描述
我有我的C ++项目文件,并想为这些源文件创建一个额外的图形用户界面。我使用Windows,MVSC2012和Qt 5.1.1与Qt Creator 2.8.1。
I have my C++ project files and want to create an additional graphical user interface for these sourcefiles. I am using windows, MVSC2012 and Qt 5.1.1 with Qt Creator 2.8.1.
所以这里是我有:
我的QtCreator项目文件夹,包括以下自动生成的文件
My QtCreator project folder, including the following auto-generated files
c:/creatorProject/creatorProject/main.cpp
c:/creatorProject/creatorProject/mainwindow.cpp
c:/creatorProject/creatorProject/mainwindow.h
c:/creatorProject/creatorProject/mainwindow.ui
c:/creatorProject/creatorProject/creatorProject.pro
c:/creatorProject/creatorProject/creatorProject.pro.user
源文件与逻辑在一个单独的文件夹,例如
Furthermore I the source files with the "logic" in a separated folder, e.g.
c:/programLogic/myFunctions.h
c:/programLogic/myFunctions.cpp
所以我只想添加这些文件到我的QtCreator项目,可以例如包含myFunctions.h并使用它。
So I simply want to add these files to my QtCreator project so that I can e.g. include "myFunctions.h" and work with it.
我的尝试:我使用Qt Creator并添加了 myFunctions.h <通过使用creatorProject >>右键单击>>添加现有文件..分别在 myFunctions.cpp 之后,我的creatorProject.pro看起来像这样:
My attempt: I used Qt Creator and added myFunctions.h respectively myFunctions.cpp by using "creatorProject >> right click >> add existing file..". After doing that my creatorProject.pro looks like this:
[...]
SOURCES += main.cpp\
mainwindow.cpp \
../../programLogic/myFunctions.cpp
HEADERS += mainwindow.h \
../../programLogic/myFunctions.h
看起来完全正常。 Qt Creator甚至在项目浏览器中显示这些文件!但是我有麻烦使用myFunctions.h在mainwindow.cpp。
Looks totally fine for me. Qt Creator even shows these files within the project explorer! However I have trouble using myFunctions.h within mainwindow.cpp.
#include "myFunctions.h" // Include can not be found
#include "../../programLogic/myFunctions.h" // Include is found but I get linker errors since myFunctions.cpp is not compiled?!
我的设置有什么问题?
推荐答案
您还需要在 .pro
文件中添加 INCLUDEPATH
You need to add the INCLUDEPATH
also in your .pro
file.
如下:
INCLUDEPATH += "C:/programLogic"
这篇关于QtCreator:如何编译外部源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!