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 23.5k 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
    18 Nov 2016, 11:03

    tried that, two.

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

    Is it possible that qmake ignores INCLUDEPATH?

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 18 Nov 2016, 11:07 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 18 Nov 2016, 11:24 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?

      M 1 Reply Last reply 18 Nov 2016, 11:30
      0
      • B Binary91
        18 Nov 2016, 11:24

        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?

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 18 Nov 2016, 11:30 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 18 Nov 2016, 11:32 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...

          M J 2 Replies Last reply 18 Nov 2016, 11:33
          0
          • B Binary91
            18 Nov 2016, 11:32

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

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

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 18 Nov 2016, 11:33 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
              18 Nov 2016, 11:32

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

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

              J Online
              J Online
              jsulm
              Lifetime Qt Champion
              wrote on 18 Nov 2016, 11:46 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 18 Nov 2016, 11:54 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

                J 4 Replies Last reply 18 Nov 2016, 12:04
                0
                • B Binary91
                  18 Nov 2016, 11:54

                  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

                  J Online
                  J Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on 18 Nov 2016, 12:04 last edited by
                  #29

                  @Binary91 You should read the Qt documentation. The moc_ files are generated for you using moc tool. Take a look at the build directory.

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

                  1 Reply Last reply
                  0
                  • B Binary91
                    18 Nov 2016, 11:54

                    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

                    J Online
                    J Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on 18 Nov 2016, 12:07 last edited by
                    #30

                    @Binary91 Why do you have a main.h? This is quite unusual.

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

                    1 Reply Last reply
                    0
                    • B Binary91
                      18 Nov 2016, 11:54

                      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

                      J Online
                      J Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on 18 Nov 2016, 12:09 last edited by
                      #31

                      @Binary91 For QApplication you need QT += gui, else you should use QCoreApplication.

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

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        Buckwheat
                        wrote on 18 Nov 2016, 12:09 last edited by
                        #32

                        @jsulm , why would you include the MOC files? I "never" include the MOC files in my source because they get generated, compiled, and linked after the normal build. The only generated file I would include is the ui_NameOfForm.h file created when using the form designer. And, only in the CPP for the UI class.

                        @Binary91 , I am sure it was explained that INCLUDEPATH tells qmake where to find common include files. I use it for 3rd party libraries or pre-built packages I developed for Qt (I treat them like 3rd party libraries). And, as I know you know... always run qmake after changing a PRO file.

                        There is one curious item I have found about QtCreator though... if you are using static libraries (even if your dependencies are setup) and make a change to a CPP file in the library... Press build-all and it will build the library and NOT re-link the application or shared library that depends on that static library. Kind of annoying but I just get around it!

                        Dave Fileccia

                        J 1 Reply Last reply 18 Nov 2016, 12:58
                        1
                        • B Offline
                          B Offline
                          Binary91
                          wrote on 18 Nov 2016, 12:09 last edited by
                          #33

                          I know what moc files are, but they were not permanently created by QtCreator (not in my build folder).
                          But can you tell me why I should have to generate them and manually include them when it works to simply add the headers to the project?
                          I mean, I wanted to reduce work by using INCLUDEPATH and NOT adding all the included headers.
                          Generating moc files and manually adding them is not reducing but increasing work.

                          Also I do not understand why I should include them when I don't need it if I add the headers directly...

                          J 1 Reply Last reply 18 Nov 2016, 12:14
                          0
                          • B Binary91
                            18 Nov 2016, 11:54

                            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

                            J Online
                            J Online
                            jsulm
                            Lifetime Qt Champion
                            wrote on 18 Nov 2016, 12:10 last edited by
                            #34

                            @Binary91 Where is myudp.cpp ?

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

                            J 1 Reply Last reply 18 Nov 2016, 12:11
                            0
                            • J jsulm
                              18 Nov 2016, 12:10

                              @Binary91 Where is myudp.cpp ?

                              J Online
                              J Online
                              jsulm
                              Lifetime Qt Champion
                              wrote on 18 Nov 2016, 12:11 last edited by
                              #35

                              @jsulm With some fixes I can build your project.
                              pro file:

                              QT       += core network
                              
                              QT       -= gui
                              
                              TARGET = test
                              CONFIG   += console
                              CONFIG   -= app_bundle
                              
                              TEMPLATE = app
                              
                              INCLUDES += lib/headers/myQLineEdit.h
                              
                              SOURCES += main.cpp \
                                  #myudp.cpp
                              
                              #HEADERS += \
                              #    myudp.h
                              

                              main.cpp

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

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

                              1 Reply Last reply
                              1
                              • B Binary91
                                18 Nov 2016, 12:09

                                I know what moc files are, but they were not permanently created by QtCreator (not in my build folder).
                                But can you tell me why I should have to generate them and manually include them when it works to simply add the headers to the project?
                                I mean, I wanted to reduce work by using INCLUDEPATH and NOT adding all the included headers.
                                Generating moc files and manually adding them is not reducing but increasing work.

                                Also I do not understand why I should include them when I don't need it if I add the headers directly...

                                J Online
                                J Online
                                jsulm
                                Lifetime Qt Champion
                                wrote on 18 Nov 2016, 12:14 last edited by
                                #36

                                @Binary91 Where I did say you have to create moc_ files manually?
                                They are generated for you. And they are completely unrelated to your problem!

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

                                1 Reply Last reply
                                1
                                • B Offline
                                  B Offline
                                  Binary91
                                  wrote on 18 Nov 2016, 12:18 last edited by
                                  #37

                                  It's getting strange now :-D

                                  What is a myudp.cpp ?? I didn't ever used this...

                                  @jsulm
                                  But you are including the header directly now. That is exaclty what I tried to avoid...

                                  Why is main.h unusual? I think using headers as a bundle of #include directives for my purposes is the correct way, so in the source file, there only exists one #include directive to its corresponding header file. Not good?

                                  J 2 Replies Last reply 18 Nov 2016, 12:22
                                  0
                                  • B Binary91
                                    18 Nov 2016, 12:18

                                    It's getting strange now :-D

                                    What is a myudp.cpp ?? I didn't ever used this...

                                    @jsulm
                                    But you are including the header directly now. That is exaclty what I tried to avoid...

                                    Why is main.h unusual? I think using headers as a bundle of #include directives for my purposes is the correct way, so in the source file, there only exists one #include directive to its corresponding header file. Not good?

                                    J Online
                                    J Online
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 18 Nov 2016, 12:22 last edited by
                                    #38

                                    @Binary91 That is what you uploaded:

                                    SOURCES += main.cpp \
                                        myudp.cpp
                                    

                                    main.h is unusual because there is no need for it. You only need a header file if you need to include some functionality provided in one source code file in another one. Where do you want to include main.h and why (and please do not say in main.cpp, because there is no need to do it this way)?
                                    I will try to change your project to use INCLUDEPATH.

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

                                    1 Reply Last reply
                                    0
                                    • B Binary91
                                      18 Nov 2016, 12:18

                                      It's getting strange now :-D

                                      What is a myudp.cpp ?? I didn't ever used this...

                                      @jsulm
                                      But you are including the header directly now. That is exaclty what I tried to avoid...

                                      Why is main.h unusual? I think using headers as a bundle of #include directives for my purposes is the correct way, so in the source file, there only exists one #include directive to its corresponding header file. Not good?

                                      J Online
                                      J Online
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 18 Nov 2016, 12:23 last edited by
                                      #39

                                      @Binary91 It builds here if I do:

                                      QT       += core network
                                      
                                      QT       -= gui
                                      
                                      TARGET = test
                                      CONFIG   += console
                                      CONFIG   -= app_bundle
                                      
                                      TEMPLATE = app
                                      
                                      #INCLUDES += lib/headers/myQLineEdit.h
                                      INCLUDEPATH += lib/headers
                                      
                                      SOURCES += main.cpp
                                      

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

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        Binary91
                                        wrote on 18 Nov 2016, 12:26 last edited by
                                        #40

                                        I really don't know from where this "myudp.cpp" comes. Maybe a de-zipping error. That should mean "lib/sources/myQLineEdit.cpp"

                                        Yeah this way its getting built on my computer as well, but there you manually added the header file to the project:
                                        INCLUDES += ...
                                        or
                                        HEADERS +=...

                                        That is what I try to avoid by using INCLUDEPATH. That was what the discussion is all about...

                                        J 1 Reply Last reply 18 Nov 2016, 12:28
                                        0
                                        • B Binary91
                                          18 Nov 2016, 12:26

                                          I really don't know from where this "myudp.cpp" comes. Maybe a de-zipping error. That should mean "lib/sources/myQLineEdit.cpp"

                                          Yeah this way its getting built on my computer as well, but there you manually added the header file to the project:
                                          INCLUDES += ...
                                          or
                                          HEADERS +=...

                                          That is what I try to avoid by using INCLUDEPATH. That was what the discussion is all about...

                                          J Online
                                          J Online
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 18 Nov 2016, 12:28 last edited by
                                          #41

                                          @Binary91 Where did I add the header file manually?
                                          I commented out the old line, please take a look again:

                                          QT       += core network
                                          
                                          QT       -= gui
                                          
                                          TARGET = test
                                          CONFIG   += console
                                          CONFIG   -= app_bundle
                                          
                                          TEMPLATE = app
                                          
                                          #INCLUDES += lib/headers/myQLineEdit.h <-- this line is commented out
                                          INCLUDEPATH += lib/headers
                                          
                                          SOURCES += main.cpp
                                          

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

                                          1 Reply Last reply
                                          0

                                          31/50

                                          18 Nov 2016, 12:09

                                          • Login

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