Home > Mobile >  Integrating C class from subfolder in QML
Integrating C class from subfolder in QML

Time:09-24

I am currently working on a c integration to QML and so far everything worked fine. I got my backend classes exposed and working. Now that I expanded my application I wanted to split my c backend into subfolders to have a better project overview. Now I'm running into linking issues where the backend files which are in those subfolders can not be found anymore. Since I am using some libraries that require a certain compiler I am using MSVC 16 and it throws the following error:

Cannot open include file: 'loginstate.h': No such file or directory. 

The parsing works fine and QtCreator does not mark the include as wrong.

When building, it creates a file called application.metatypes.json. In said file all the information about the exposed classes is stored. When reading through it, I found that loginstates.h is supposed to be in the root directory where it actually is not, it is in a subfolder of root. When i change it manually to the proper folder, my application runs.

Is there a way to get qmake/moc to generate the proper path for classes in subfolders? What setting am I missing?

The .pro file:

QT = core quick serialport network virtualkeyboard

TEMPLATE = app

CONFIG  = qt c  17 warn_on qmltypes
CONFIG -= debug_and_release debug_and_release_target

SOURCES  = \
    main.cpp \
    datetimebackend.cpp \
    footerbackend.cpp \
    labelbuttonbackend.cpp \
    globaluisettings.cpp \
    headerbackend.cpp \
    scannerbuttonbackend.cpp \
    sidebarbackend.cpp

HEADERS  = \
    bussinessLogic/loginstate.h \
    datetimebackend.h \
    footerbackend.h \
    globaluisettings.h \
    headerbackend.h \
    labelbuttonbackend.h \
    scannerbuttonbackend.h \
    sidebarbackend.h

RESOURCES  = qml.qrc

RC_ICONS = ./images/icon.ico

INCLUDEPATH  = $$PWD/..

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH  = $$PWD

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

QML_IMPORT_NAME = Backend
QML_IMPORT_MAJOR_VERSION = 1

DISTFILES  = some qml files

CodePudding user response:

You get those errors just because some header files are not in path and the compiler cannot find them. As you said that you restructured the directory template, you will only need to add appropriate include paths to the INCLUDEPATH parameter in your .pro file like :

INCLUDEPATH  = $$PWD/new/include/path

Do it for every directory where contains a .h file that is not being found by the compiler.

  • Related