0

I am trying to setup something very simple but the QML is not resolving my module. Why?

I just following the tutorial below, but it does not use cmake, not sure if this is cmake issue or code.

https://www.youtube.com/watch?v=yTH5e6atHoE

I created a "Colors" subdirectory on my folder structure with a qmldir and "CustomColors_01.qml"

here is my cmake file list:

qt_add_qml_module(appDlgDemo
    URI DlgDemo
    VERSION 1.0
    QML_FILES main.qml
    QML_FILES Colors/CustomColors_01.qml
    QML_FILES Colors/qmldir
)

My folder structure:

-
│   .gitignore
│   CMakeLists.txt
│   main.cpp
│   main.qml
│
└───Colors
        CustomColors_01.qml
        qmldir

the qmldir

module Colors
singleton CustomColors 1.0 CustomColors_01.qml

the Colors/CustomColors_01.qml

pragma Singleton

import QtQuick

QtObject{
    readonly property string background: "#f6f9f8"
}

the main.qml and it won't resolve "import Colors 1.0", only if I import directly, but this is not what I need.

enter image description here

gmmo
  • 2,577
  • 3
  • 30
  • 56
  • 1
    Hi, I did not try it with cmake, but adding the *parent directory path* such as `qrc:/` to `engine.addImportPath` might solve the problem, as I did in my [custom theme](https://github.com/SMR76/qml-snow-white#usage). – SMR Sep 13 '22 at 23:00
  • 1
    Agreed, I would use `import "Colors"` – Stephen Quan Sep 14 '22 at 05:32

0 Answers0