Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Basic question: Including headers with INCLUDEPATH doesn't work
Forum Updated to NodeBB v4.3 + New Features

Basic question: Including headers with INCLUDEPATH doesn't work

Scheduled Pinned Locked Moved General and Desktop
50 Posts 5 Posters 24.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Binary91

    @mrjj said in Basic question: Including headers with INCLUDEPATH doesn't work:

    You should not have to include any standard Qt cpp files. the .H is enough.

    Yeah but why do I have to with my own headers? Is there a list of pre-defined standard headers and their corresponding sources so compiler/linker knows that automatically? If yes, couldn't that list be extended by own headers/sources?

    but if you write .pro file BY HAND make sure u include
    TEMPLATE = app
    and stuff like
    QT += core gui
    Else it wont link Qt to it!!

    I do not create the whole project file by myself, QtCreator does that so all that stuff is included.

    Is the file
    libA.cpp IN THE SAME FOLDER as main.cpp ?

    Nope, should it? I thought that exactly this could be avoided by setting an INCLUDEPATH, isn't it? I thought that after setting this path, the compiler/linker knows where to search for those headers, otherwise this INCLUDEPATH doesn't have any sense or am I missing something?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #9

    @Binary91 said in Basic question: Including headers with INCLUDEPATH doesn't work:

    Nope, should it?

    Well it dont matter where it is, BUT you say it is in same folder!
    So it cant find them and hence it dont like your test::test() as it never saw the .cpp file.

    also INCLUDEPATH is for .H files and NOT .cpp files!

    SOURCE is for .cpp files and iy MUST be correct path

    like where where my xml lib is somewhere else
    SOURCES += main.cpp
    Configuration.cpp
    Forms/AbstractForm.cpp \ <<<--------------- in a sub folder called Forms
    Forms/ConfigurationForm.cpp
    Forms/DefaultFormFooter.cpp \
    ../../Common/XML/pugixml-1.5/src/pugixml.cpp \

    Look at the pugixml.cpp, here i tell it to go back 2 folders and into Common

    So when you say

    SOURCES += main.cpp \ CORRECT
    libA.cpp \ WRONG. AS ITS NOT THERE
    libB.cpp Also wrong ?

    B 1 Reply Last reply
    3
    • mrjjM mrjj

      @Binary91 said in Basic question: Including headers with INCLUDEPATH doesn't work:

      Nope, should it?

      Well it dont matter where it is, BUT you say it is in same folder!
      So it cant find them and hence it dont like your test::test() as it never saw the .cpp file.

      also INCLUDEPATH is for .H files and NOT .cpp files!

      SOURCE is for .cpp files and iy MUST be correct path

      like where where my xml lib is somewhere else
      SOURCES += main.cpp
      Configuration.cpp
      Forms/AbstractForm.cpp \ <<<--------------- in a sub folder called Forms
      Forms/ConfigurationForm.cpp
      Forms/DefaultFormFooter.cpp \
      ../../Common/XML/pugixml-1.5/src/pugixml.cpp \

      Look at the pugixml.cpp, here i tell it to go back 2 folders and into Common

      So when you say

      SOURCES += main.cpp \ CORRECT
      libA.cpp \ WRONG. AS ITS NOT THERE
      libB.cpp Also wrong ?

      B Offline
      B Offline
      Binary91
      wrote on last edited by
      #10

      @mrjj said in Basic question: Including headers with INCLUDEPATH doesn't work:

      @Binary91 said in Basic question: Including headers with INCLUDEPATH doesn't work:

      Nope, should it?

      Well it dont matter where it is, BUT you say it is in same folder!
      So it cant find them and hence it dont like your test::test() as it never saw the .cpp file.

      also INCLUDEPATH is for .H files and NOT .cpp files!

      SOURCE is for .cpp files and iy MUST be correct path

      like where where my xml lib is somewhere else
      SOURCES += main.cpp
      Configuration.cpp
      Forms/AbstractForm.cpp
      Forms/ConfigurationForm.cpp
      Forms/DefaultFormFooter.cpp \
      ../../Common/XML/pugixml-1.5/src/pugixml.cpp \

      Look at the pugixml.cpp, here i tell it to go back 2 folders and into Common

      So when you say

      SOURCES += main.cpp \ CORRECT
      libA.cpp \ WRONG. AS ITS NOT THERE
      libB.cpp Also wrong ?

      Yep I know that know and already fixed this. But I don't know why I have to set the full path of the header files after setting INCLUDEPATH?!

      That is how my project file looks like now:

      INCLUDEPATH += C:/Qt/lib/headers
      
      SOURCES += main.cpp \
      C:/Qt/lib/sources/libA.cpp \
      C:/Qt/lib/sources/libB.cpp
      
      HEADERS += main.h
      

      It still throws these errors...
      When I include those headers manually like I did with the sources, everything works fine. BUT I thought that I could avoid this with INCLUDEPATH...

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #11

        Well normally you do not need to do so...

        INCLUDEPATH += ../../Common/CONET
        ../../Common/XML/pugixml-1.5/src/ \

        the pugixml.h is in the src and i can just use
        it like
        #include "pugixml.h"

        B 1 Reply Last reply
        0
        • mrjjM mrjj

          Well normally you do not need to do so...

          INCLUDEPATH += ../../Common/CONET
          ../../Common/XML/pugixml-1.5/src/ \

          the pugixml.h is in the src and i can just use
          it like
          #include "pugixml.h"

          B Offline
          B Offline
          Binary91
          wrote on last edited by
          #12

          @mrjj
          What could cause that problems then? Do I have to change some build settings in QtCreator?

          I mean, there is no error in the code, because after manually adding those headers to the project , like:

          HEADERS += C:/Qt/lib/headers/libA.h
          

          works without problems.
          BUT something like this:

          HEADERS += libA.h
          

          also doesn't work!

          I don't know what could be wrong. INCLUDEPATH does have an effect to QtCreator, because when I try to include one of my own headers, it searches and autofills the name of the header file. So QtCreator searches for those files in the INCLUDEPATH I set, but it can't combine them when trying to build the project...

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #13

            No, it works that way. pr default. Nothing I have seen in Creator adjust that.
            Only thing that can go wrong is path is invalid ( on windows, spaces in path can be issue)

            HEADERS += libA.h

            Will work if the libA.h is in the same folder as the .pro file
            Else its FALSE and will not work.

            B 1 Reply Last reply
            0
            • mrjjM mrjj

              No, it works that way. pr default. Nothing I have seen in Creator adjust that.
              Only thing that can go wrong is path is invalid ( on windows, spaces in path can be issue)

              HEADERS += libA.h

              Will work if the libA.h is in the same folder as the .pro file
              Else its FALSE and will not work.

              B Offline
              B Offline
              Binary91
              wrote on last edited by
              #14

              @mrjj
              I found out that the problem only appears to a few header files!

              I include 3 headers, each declaring a subclass of a standard Qt class:

              INCLUDEPATH += C:/Qt/lib/headers
              
              HEADERS += main.h
              
              SOURCES += main.cpp \
              myQLineEdit.cpp \
              myQPushButton.cpp \
              myQString.cpp
              

              The errors appear to the functions defined in the source files myQLineEdit.cpp and myQPushButton.cpp, but NOT in myQString.cpp!

              I think I got the problem!! In myQLineEdit and myQPushButton class, I do have a Q_OBJECT. Can this cause the problems??

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #15

                Q_OBJECT is used by a tool called moc.exe to help make signals and slot possible
                It should not to anything with regards to include files. :)
                As far as I have ever seen.

                1 Reply Last reply
                2
                • B Offline
                  B Offline
                  Binary91
                  wrote on last edited by
                  #16

                  that is really annoying..
                  Why do those undefind reference errors appear to some of my source files but not to all of them?
                  Don't know where to search for an answer now

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    Binary91
                    wrote on last edited by
                    #17

                    By the way:
                    the problem really is Q_OBJECT...

                    I just wrote "Q_OBJECT" into the myQString class and look what happened: undefined reference vtable ... in myQString.cpp!

                    So Q_OBJECT makes the problems why I have to add all headers to the project! How can I avoid this?

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #18

                      when u add Q_OBJECT, please run qmake!

                      1 Reply Last reply
                      2
                      • B Offline
                        B Offline
                        Binary91
                        wrote on last edited by
                        #19

                        I already tried that.
                        Building, running
                        Building, qmake, running
                        qmake, running
                        qmake, building, running

                        None of the above ways succeded

                        mrjjM 1 Reply Last reply
                        0
                        • B Binary91

                          I already tried that.
                          Building, running
                          Building, qmake, running
                          qmake, running
                          qmake, building, running

                          None of the above ways succeded

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #20

                          @Binary91
                          then please as last test
                          Complete delete the build folder.

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            Binary91
                            wrote on last edited by
                            #21

                            tried that, two.

                            Deleted everything but my project file and the sources/headers. Didn't work :-(

                            Is it possible that qmake ignores INCLUDEPATH?

                            mrjjM 1 Reply Last reply
                            1
                            • B Binary91

                              tried that, two.

                              Deleted everything but my project file and the sources/headers. Didn't work :-(

                              Is it possible that qmake ignores INCLUDEPATH?

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #22

                              @Binary91
                              Well anything seems possible with your setup. :)
                              Q_OBJECT should not bork anything.

                              Im out of ideas :)

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                Binary91
                                wrote on last edited by Binary91
                                #23

                                Well, I'll post the whole project file, its headers and sources and maybe you can copy/paste it and try to run it with?

                                If it works, then it is a setting problem. If not, something with my include logic doesn't work.

                                project file:

                                #-------------------------------------------------
                                #
                                # Project created by QtCreator 2016-11-17T15:45:17
                                #
                                #-------------------------------------------------
                                
                                QT       += core gui
                                
                                greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                                
                                TARGET = CourseCalculator
                                TEMPLATE = app
                                
                                INCLUDEPATH += C:/Qt/lib/headers
                                
                                HEADERS  += main.h
                                
                                SOURCES += main.cpp
                                           C:/Qt/lib/sources/myQString.cpp \
                                           C:/Qt/lib/sources/myQLineEdit.cpp \
                                           C:/Qt/lib/sources/myQPushButton.cpp
                                
                                

                                main.cpp:

                                // main.cpp
                                
                                #include "main.h"
                                
                                int main(int argc, char *argv[])
                                {
                                  QApplication applicationApp(argc, argv);
                                  clsWindowMain windowMain;
                                
                                  QTimer::singleShot(0, &windowMain, SLOT(slotStart()));
                                  int ret = applicationApp.exec();
                                  return ret;
                                }
                                
                                main.h:
                                

                                // main.h

                                #ifndef MAIN_H
                                #define MAIN_H
                                
                                #include <QApplication>
                                #include <QTimer>
                                #include <QWidget>
                                #include <QDialog>
                                
                                #endif // MAIN_H
                                

                                myQLineEdit.h:

                                // myQLineEdit.h
                                
                                #ifndef MYQLINEEDIT_H
                                #define MYQLINEEDIT_H
                                
                                #include <QDebug>
                                #include <QLineEdit>
                                #include <QMessageBox>
                                #include <QDir>
                                
                                
                                // forward declaration
                                
                                class myQLineEdit;
                                
                                
                                // declaration
                                
                                class myQLineEdit : public QLineEdit
                                {
                                  Q_OBJECT
                                
                                  // .. properties
                                
                                  public:
                                    myQLineEdit(QWidget* widgetParent = 0);
                                    ~myQLineEdit();
                                
                                    // .. more methods
                                };
                                
                                #endif
                                
                                

                                myQLineEdit.cpp:

                                // myQLineEdit.cpp
                                
                                #include <myQLineEdit.h> // absolute path or absolute path with whitespaces also doesn't work
                                
                                
                                // ----- constructors -----
                                
                                myQLineEdit::myQLineEdit(QWidget* widgetParent) : QLineEdit(widgetParent)
                                {
                                   // stuff
                                }
                                

                                Is that compilable for you?

                                mrjjM 1 Reply Last reply
                                0
                                • B Binary91

                                  Well, I'll post the whole project file, its headers and sources and maybe you can copy/paste it and try to run it with?

                                  If it works, then it is a setting problem. If not, something with my include logic doesn't work.

                                  project file:

                                  #-------------------------------------------------
                                  #
                                  # Project created by QtCreator 2016-11-17T15:45:17
                                  #
                                  #-------------------------------------------------
                                  
                                  QT       += core gui
                                  
                                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                                  
                                  TARGET = CourseCalculator
                                  TEMPLATE = app
                                  
                                  INCLUDEPATH += C:/Qt/lib/headers
                                  
                                  HEADERS  += main.h
                                  
                                  SOURCES += main.cpp
                                             C:/Qt/lib/sources/myQString.cpp \
                                             C:/Qt/lib/sources/myQLineEdit.cpp \
                                             C:/Qt/lib/sources/myQPushButton.cpp
                                  
                                  

                                  main.cpp:

                                  // main.cpp
                                  
                                  #include "main.h"
                                  
                                  int main(int argc, char *argv[])
                                  {
                                    QApplication applicationApp(argc, argv);
                                    clsWindowMain windowMain;
                                  
                                    QTimer::singleShot(0, &windowMain, SLOT(slotStart()));
                                    int ret = applicationApp.exec();
                                    return ret;
                                  }
                                  
                                  main.h:
                                  

                                  // main.h

                                  #ifndef MAIN_H
                                  #define MAIN_H
                                  
                                  #include <QApplication>
                                  #include <QTimer>
                                  #include <QWidget>
                                  #include <QDialog>
                                  
                                  #endif // MAIN_H
                                  

                                  myQLineEdit.h:

                                  // myQLineEdit.h
                                  
                                  #ifndef MYQLINEEDIT_H
                                  #define MYQLINEEDIT_H
                                  
                                  #include <QDebug>
                                  #include <QLineEdit>
                                  #include <QMessageBox>
                                  #include <QDir>
                                  
                                  
                                  // forward declaration
                                  
                                  class myQLineEdit;
                                  
                                  
                                  // declaration
                                  
                                  class myQLineEdit : public QLineEdit
                                  {
                                    Q_OBJECT
                                  
                                    // .. properties
                                  
                                    public:
                                      myQLineEdit(QWidget* widgetParent = 0);
                                      ~myQLineEdit();
                                  
                                      // .. more methods
                                  };
                                  
                                  #endif
                                  
                                  

                                  myQLineEdit.cpp:

                                  // myQLineEdit.cpp
                                  
                                  #include <myQLineEdit.h> // absolute path or absolute path with whitespaces also doesn't work
                                  
                                  
                                  // ----- constructors -----
                                  
                                  myQLineEdit::myQLineEdit(QWidget* widgetParent) : QLineEdit(widgetParent)
                                  {
                                     // stuff
                                  }
                                  

                                  Is that compilable for you?

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #24

                                  @Binary91
                                  would be very much easier if you zipped folder and shared via dropbox or g drive as
                                  copy paste to real files again is very error prone and time consuming :)

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    Binary91
                                    wrote on last edited by
                                    #25

                                    Good idea. But my dropbox accout has no free memory left :-D

                                    Have to create a new account first, maybe on g drive...

                                    mrjjM jsulmJ 2 Replies Last reply
                                    0
                                    • B Binary91

                                      Good idea. But my dropbox accout has no free memory left :-D

                                      Have to create a new account first, maybe on g drive...

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by mrjj
                                      #26

                                      @Binary91
                                      well a zipped project is ultra small. so delete/remove something for a moment and it should have space :)

                                      btw: G Drive is 15 GB but the client is nowhere near as nice as dropbox.

                                      1 Reply Last reply
                                      1
                                      • B Binary91

                                        Good idea. But my dropbox accout has no free memory left :-D

                                        Have to create a new account first, maybe on g drive...

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #27

                                        @Binary91 If you derive from Qt classes which are derived from QObject then you need to include the generated moc_ files.
                                        For example in myQLineEdit.cpp add

                                        #include "moc_myQLineEdit.cpp"
                                        

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        1
                                        • B Offline
                                          B Offline
                                          Binary91
                                          wrote on last edited by Binary91
                                          #28

                                          but from where do I get this moc file?
                                          If I try to include, compiler gives me an error that it can not find such file or directory

                                          btw:
                                          https://www.dropbox.com/s/whqdkcat767224t/test.zip?dl=0

                                          jsulmJ 4 Replies Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved