Skip to content

Usage in Qbs

Here is a short example. Click on to see the explanation.

example/example.qbs
import qbs.FileInfo

CppApplication {
    Depends {
        name: 'Qt'
        submodules: ['core', 'gui', 'qml', 'quick']
        versionAtLeast: '6.5'
    }

    Depends { name: 'easy.qmldir' }  // (1)!

    name: 'easy-qmldir-qml-example'

    Qt.qml.importName: 'easy.qmldir.example'  // (2)!
    Qt.qml.importVersion: '1.0'               // (3)!

    easy.qmldir.plugin: undefined  // (4)!

    Group {
        name: 'C++ files'
        prefix: 'src/'
        files: ['**/*.cpp', '**/*.hpp']
    }

    Group {
        name: 'QML files'
        files: ['**']
        prefix: 'qml/'
        Qt.core.resourceSourceBase: 'qml/'
        Qt.core.resourcePrefix: '/qt/qml/'
        fileTags: [
            'qt.core.resource_data',  // (5)!
            'easy.qmldir.inputs'      // (6)!
        ]
    }

    EasyQmldir {  // (7)!
        Qt.core.resourcePrefix: '/qt/qml/easy/qmldir/example/'
        fileTags: ['qt.core.resource_data']
    }
}
  1. Add a dependency on the easy.qmldir module in your product.
  2. Don't forget to set the module name via Qt.qml.importName.
  3. Set the module version using Qt.qml.importVersion.
  4. In this case, the product is not a QML engine extension but an application, so there is no plugin. Disable generation by setting it to undefined.
  5. Tag with qt.core.resource_data to pack QML-files into Qt resources.
  6. Tag with easy.qmldir.inputs to list the QML-files in the generated qmldir.
  7. You can use EasyQmldir item to easily grab the generated qmldir for further packing into resources (like here) or, for example, for installation via qbs.install: true.

You can run this example yourself! Just go to the module’s root folder and execute:

qbs run

Output

The resulting qmldir looks like this:

qmldir
module easy.qmldir.example
typeinfo plugins.qmltypes

singleton Global 1.0 Global.qml
Main 1.0 Main.qml