Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Move header and source files to different location
QtWS25 Last Chance

Move header and source files to different location

Scheduled Pinned Locked Moved Solved Installation and Deployment
projectheaderssources
6 Posts 3 Posters 3.8k Views
  • 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.
  • S Offline
    S Offline
    szumial
    wrote on last edited by
    #1

    Hi! I'm having an issue with restructuring my project. I would like to move the header files to a new folder named "include" and the source files to another one named "src". I have done it successfully for another project in the past, just by copy-pasting and adjusting the .pro file. However, I am not able to do it on this new project - the files are not properly recognized by Qt Creator. What steps am I missing here?

    My .pro file looks like this at the moment:

    TEMPLATE = lib
    CONFIG += dll
    DEFINES += MYNTERFACE_LIBRARY
    DESTDIR = $$PWD/lib/
    
    !contains(DEFINES, _ENABLE_QT_GUI) {
    QT -= gui
    } # !contains(DEFINES, _ENABLE_QT_GUI)
    
    unix {
        target.path = /usr/lib
    }
    !isEmpty(target.path): INSTALLS += target
    
    contains(DEFINES, _STATIC_BUILD) {
    CONFIG -= dll
    CONFIG += staticlib
    } # contains(DEFINES, _STATIC_BUILD)
    
    CONFIG += c++11
    
    # Compiler / Linker Options 
    
    CONFIG(debug, debug|release) {
    TARGET = Mynterfaced
    } else {
    TARGET = MyInterface
    } # CONFIG(debug, debug|release)
    
    unix {
        target.path = /usr/lib
    }
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        MyInterface_global.h \
        myinterface.h \
        precompiled.h
    
    SOURCES += \
        myinterface.cpp \
    

    I would like the headers and sources to be located as follows:

    HEADERS += \
        include/MyInterface_global.h \
        include/myinterface.h \
        include/precompiled.h
    
    SOURCES += \
        src/myinterface.cpp \
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That looks good.

      What errors do you get ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        szumial
        wrote on last edited by
        #3

        After moving the files and adjusting the .pro, the myinterface.cpp source can't find the included header. I am getting the following messages:
        error: 'myinterface.h' file not found
        error: use of undeclared identifier 'MyInterface'

        After changing the way I include the header in this source from:

        #include "myinterface.h"
        

        to:

        #include "include/myinterface.h"
        

        it works again. I find this strange, as previously in another project, I moved many files like this and didn't have an issue. Why is the "include/" path not recognized automatically? Am I missing somethin in the project?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @szumial said in Move header and source files to different location:

          Why is the "include/" path not recognized automatically?

          Because it's a non standard path.

          @szumial said in Move header and source files to different location:

          Am I missing somethin in the project?

          Yes you are, you need to add that path to the INCLUDEPATH variable.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • S Offline
            S Offline
            szumial
            wrote on last edited by
            #5

            Thank you :) That solves the case. However, I don't remember adding these non-standard paths in that previous project. Anyway, it works and the topic is closed :)

            jsulmJ 1 Reply Last reply
            0
            • S szumial

              Thank you :) That solves the case. However, I don't remember adding these non-standard paths in that previous project. Anyway, it works and the topic is closed :)

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

              @szumial said in Move header and source files to different location:

              I don't remember adding these non-standard paths in that previous project

              Before, your header files and source files were located in the same directory. The preprocessor searches for header files in same directory, then in directories specified using -I parameter (that is what INCLUDEPATH adds) and then in system directories.

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

              1 Reply Last reply
              2

              • Login

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