Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Why need ../ to include the path in Qt5?



  • Hi,

    I transplanted the source that was made with Qt4 to Qt5.
    Inclusion of compilation errors had out a lot.

    When an attempt is made to include the file in a different folder,
    You do not specify the ../ and it becomes a compile error.
    It was no problem in Qt4.
    Do I need something set?

    <Folder structure>

    • sample
      main.cpp
      • Model
        SampleModel.h, SampleModel.cpp
      • Data
        SampleData.h, SampleData.cpp

    <Qt4 source code of>
    / * SampleModel.h * /
    #include "Data / SampleData.h"

    <Qt5 source code of>
    #include "Data / SampleData.h" // error
    #include "../Data/SampleData.h"

    Use environment: Windows7 64bit, QtCreator 3.3.0, Qt5.4.0

    Best regards,


  • Moderators

    The paths depend on what you put in INCLUDEPATH variable in .pro file.



  • I'm sorry. I do not know what to do with.

    I tried to add a INCLUDEPATH, but you get an error.
    Error content is below.
    C1083: 'Data / SampleData.h' No such file or directory.
    @

    #Sample.pro
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = Sample
    TEMPLATE = app

    INCLUDEPATH +=
    Data \

    SOURCES += main.cpp
    Data/SampleData.cpp
    Model/SampleModel.cpp

    HEADERS +=
    Data/SampleData.h
    Model/SampleModel.h

    FORMS += \

    @
    Thank you.


  • Moderators

    Try
    @
    #include "SampleData.h"
    @

    There was no change here between Qt 4 and 5, so it really should work.



  • I solved the problem.
    It was resolved by adding a $$ PWD to include path.


    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = Sample
    TEMPLATE = app

    INCLUDEPATH += $$PWD

    SOURCES += main.cpp
    Data/SampleData.cpp
    Model/SampleModel.cpp

    HEADERS += Data/SampleData.h
    Model/SampleModel.h

    Mr. sierdzio.
    Thank you tell me.


  • Moderators

    Hm, that is unusual, but good that you've found this out. Happy coding!


Log in to reply