Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt include Class of another Project (Cannot open include file: 'foo.h')

I just started with Qt and some issues came up. I'm sure it must be a simple solution but I just can't find it.

I have two Projects, ProjectOne and ProjectTwo. I'd like you use the class foo from ProjectOne in main.cpp from ProjectTwo. When I run my Programm The Files are copied/referenced into ProjectTwo, but when i try to include foo in my main.cpp (#include "foo.h") i recieve the following error:


> main.cpp:3: error: C1083: Cannot open include file: 'foo.h':
> No such file or directory

Here's my Structure:

-ProjectOne
    -ProjectOne.pro
    -Headers
        -foo.h
    -Source
        -foo.cpp
    -Other files
        -ProjectOne.pri
-ProjectTwo
    -ProjectTwo.pro
    -ProjectOne
        -ProjectOne.pri
        -Headers
            -foo.h
        -Sources
            -foo.cpp
    -Sources
        main.cpp

Here's what i edited on my .pro and .pri files

**ProjectOne.pri**
INCLUDEPATH  += $$PWD
SOURCES      += $$PWD/foo.cpp
HEADERS      += $$PWD/foo.h

**ProjectTwo.pro:**
include(../ProjectOne/ProjectOne.pri)
QT += core
SOURCES += foo.cpp
HEADERS += foo.h

I'm using Qt Creator 3.1.2 on Windows 7. My Programming Language is C++ and I'm compiling with VisualStudio 10 Express.

Any help is greatly appreciated!

like image 588
oemay Avatar asked Jan 25 '26 04:01

oemay


1 Answers

When including a file that isn't directly in you project folder you need to include it with full or relative path.

i.e.

#include "bar/foo.h"

or

#include "../../bar/foo.h"
like image 119
John Doe Avatar answered Jan 27 '26 17:01

John Doe



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!