PDA

View Full Version : A doubt with DEPENDPATH and INCLUDEPATH



tonnot
11th March 2011, 09:06
I have a class 'myclass' with their .h/cpp files that its placed outside my project, for example "d:/my_components/".
Ok , this class extends 'basic_background', and 'basic_background' .h/cpp files is placed at the same location "d:/my_components/ (althought it can be other)

Ok, using Qtcreator designer, I must to use 'add existing files' and choose the 'myclass' and 'basic_background', because if not I cannot build the program.

How can I do to avoid this? Everytime I need to use a custom class I have to add a lot of files manually?
Includepath and dependpath does not work for me...
Any idea? Thanks

stampede
11th March 2011, 09:16
Includepath and dependpath does not work for me...
Then you are doing something wrong, because I'm always adding files by modifying .pro in text editor and never had any problems. Can you show your .pro file ?

SixDegrees
11th March 2011, 09:18
The compiler/linker are not clairvoyant; they need to be told where all the components required for a build reside.

The standard way of handling this is to build your external components into a separate library, then incorporate it into your project through the include path and the library path.

tonnot
11th March 2011, 10:49
Thanks.
So, I dont understand if the classes used by 'myclass' are at the same level (the same folder), and being specified by 'includepath' are not found...
And I dont understand how 'QTclasses' searchs used qt clases. Why or how can I do the same ?
Maybe can I write #include "../" ?
Thanks

stampede
11th March 2011, 10:59
Yes, you can use relative path in include directives, but if you have "my_class.h" in folder C:\project files\h, you can use it like:


// project.pro
...
INCLUDEPATH += "C:/project files/h"
...

// source file
#include "my_class.h"



(...) being specified by 'includepath' are not found...
Then something is wrong with the declaration - again, post the .pro file and show the code where you include the files.

tonnot
11th March 2011, 11:37
Nada.pro


QT += core gui
TARGET = nada
TEMPLATE = app
INCLUDEPATH +=D:/I_DESARROLLO/c++ok/APCplugins/aplug
SOURCES += main.cpp\
mainwindow.cpp \
../APCplugins/aplug/a_wall2.cpp

HEADERS += mainwindow.h \
../APCplugins/aplug/a_wall2.h

FORMS += mainwindow.ui

a_wall2.h

#ifndef A_WALL2_H
#define A_WALL2_H

#include <QDateTime>
#include <QTimer>
#include <widgetwithbackground.h>

When Compile I have undefined references to widgetwithbackground.h. This file is located at the same folder as a_wall2.

However this nada.pro works.


QT += core gui

TARGET = nada
TEMPLATE = app

INCLUDEPATH +=D:/I_DESARROLLO/c++ok/APCplugins/aplug


SOURCES += main.cpp\
mainwindow.cpp \
../APCplugins/aplug/a_wall2.cpp \
../APCplugins/aplug/widgetwithbackground.cpp

HEADERS += mainwindow.h \
../APCplugins/aplug/a_wall2.h \
../APCplugins/aplug/widgetwithbackground.h

FORMS += mainwindow.ui

So I f I have a class that uses 100 classes, must I to add manually all this classes that besides are placed at the same folder ?
Thanks

stampede
11th March 2011, 12:28
So I f I have a class that uses 100 classes, must I to add manually all this classes that besides are placed at the same folder ?
You need to add all files that you want to compile.
Directory name suggests that this supposed to be some kind of a "plugin", so IMHO better would be to do as SixDegrees posted - build the "aplug" into .dll and use it as library instead of compiling it with your project.

tonnot
11th March 2011, 12:57
So, finally I dont understand How QT classes can call themself.... I supose this is because they are into a dll , isn't ?
Thanks

stampede
11th March 2011, 13:36
In order to use another class and it's methods you need to know WHAT to use and HOW to do it:
- it's interface ( what you can use ... )
- implementation of each method ( ... and how )
You know the interface of the class by including it's header file. Knowing the implementation is handled by the compiler - you can compile the class with all your project sources, or link against separate library - note that you don't need to include .cpp (implementation) files of the class you want to use.

Suppose you have a class


// test.h
class Test{
public:
void method();
};
// test.cpp
void Test::method(){
}

In order to use it in your sources you need to:
a) include the class definition

//other_file.cpp
#include "test.h"

//...
Test t;
t.method();

b) compile the class implementation files (test.cpp) along with your project OR add it to your project as separate library, compiled earlier
Both a) and b) are mandatory, if you don't have a) - then errors like "Test was not declared" appears, if you don't have b) - you may see something like "undefined reference to Test::method()"

Hope it was clear enough.

tonnot
11th March 2011, 13:47
Yes. Thanks