QtCreator: How to compile external source files

心不动则不痛 提交于 2019-12-25 02:38:31

问题


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.

So here is what i have:

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

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.

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

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?!

What is wrong within my setup?


回答1:


You need to add the INCLUDEPATH also in your .pro file.

Something like:

INCLUDEPATH += "C:/programLogic"


来源:https://stackoverflow.com/questions/20421609/qtcreator-how-to-compile-external-source-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!