Results 1 to 10 of 10

Thread: A doubt with DEPENDPATH and INCLUDEPATH

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default A doubt with DEPENDPATH and INCLUDEPATH

    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

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    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 ?

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    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.

  4. #4
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    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

  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    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:
    Qt Code:
    1. // project.pro
    2. ...
    3. INCLUDEPATH += "C:/project files/h"
    4. ...
    5.  
    6. // source file
    7. #include "my_class.h"
    To copy to clipboard, switch view to plain text mode 

    (...) 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.

  6. #6
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    Nada.pro

    Qt Code:
    1. QT += core gui
    2. TARGET = nada
    3. TEMPLATE = app
    4. INCLUDEPATH +=D:/I_DESARROLLO/c++ok/APCplugins/aplug
    5. SOURCES += main.cpp\
    6. mainwindow.cpp \
    7. ../APCplugins/aplug/a_wall2.cpp
    8.  
    9. HEADERS += mainwindow.h \
    10. ../APCplugins/aplug/a_wall2.h
    11.  
    12. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    a_wall2.h
    Qt Code:
    1. #ifndef A_WALL2_H
    2. #define A_WALL2_H
    3.  
    4. #include <QDateTime>
    5. #include <QTimer>
    6. #include <widgetwithbackground.h>
    To copy to clipboard, switch view to plain text mode 

    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 Code:
    1. QT += core gui
    2.  
    3. TARGET = nada
    4. TEMPLATE = app
    5.  
    6. INCLUDEPATH +=D:/I_DESARROLLO/c++ok/APCplugins/aplug
    7.  
    8.  
    9. SOURCES += main.cpp\
    10. mainwindow.cpp \
    11. ../APCplugins/aplug/a_wall2.cpp \
    12. ../APCplugins/aplug/widgetwithbackground.cpp
    13.  
    14. HEADERS += mainwindow.h \
    15. ../APCplugins/aplug/a_wall2.h \
    16. ../APCplugins/aplug/widgetwithbackground.h
    17.  
    18. FORMS += mainwindow.ui
    To copy to clipboard, switch view to plain text mode 

    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

  7. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    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.

  8. #8
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    So, finally I dont understand How QT classes can call themself.... I supose this is because they are into a dll , isn't ?
    Thanks

  9. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    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
    Qt Code:
    1. // test.h
    2. class Test{
    3. public:
    4. void method();
    5. };
    6. // test.cpp
    7. void Test::method(){
    8. }
    To copy to clipboard, switch view to plain text mode 
    In order to use it in your sources you need to:
    a) include the class definition
    Qt Code:
    1. //other_file.cpp
    2. #include "test.h"
    3.  
    4. //...
    5. Test t;
    6. t.method();
    To copy to clipboard, switch view to plain text mode 
    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.

  10. #10
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A doubt with DEPENDPATH and INCLUDEPATH

    Yes. Thanks

Similar Threads

  1. INCLUDEPATH how it works ?
    By tonnot in forum Newbie
    Replies: 23
    Last Post: 29th October 2010, 09:53
  2. QMake DEPENDPATH
    By lalesculiviu in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2010, 14:21
  3. Replies: 1
    Last Post: 2nd December 2008, 11:31
  4. another qmake INCLUDEPATH spaces problem
    By mmueller in forum Qt Programming
    Replies: 4
    Last Post: 31st July 2008, 14:12
  5. qmake INCLUDEPATH with spaces
    By bitChanger in forum Qt Programming
    Replies: 8
    Last Post: 28th April 2006, 05:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.