重用 Qt Quick Ultralite QML 对象采用 Qt QML

Qt Quick Ultralite's Qt QML compatibility modules

Qt Quick Ultralite provides compatibility modules to let you use Qt Quick Ultralite QML objects with Qt QML. The modules are located in Qul_DIR/compatibility .

Qt Quick Ultralite offers the following compatibility modules:

Name Minimum version
Extras 1.0
Layers 1.7

注意: Every module can be imported with the minor version number of the currently installed package.

To use any of the modules one must add the Qul_DIR/compatibility directory to the QML import path and import the desired module in the .qml 文件:

注意: The modules require Qt 5.15 .

Import the Qt Quick Ultralite Extras and Qt Quick Ultralite Layers modules.

// sample main.cpp file
...
int main(int argc, char *argv[])
{
    ...
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.addImportPath("Qul_DIR/compatibility");
    ...
    return app.exec();
}
							
// sample main.qml file
import QtQuick 2.15
...
import QtQuickUltralite.Extras 1.7
Window {
    ...
    StaticText {
        text: "Hello World!"
    }
}
							

注意: Extras module uses C++ and therefore the module's binaries must match with the user's project configuration.

To take advantage of Qt Creator's code completion, append the Qul_DIR/compatibility directory to the QML_IMPORT_PATH .

构建

The Qt Quick Ultralite source package provides sources for the modules, which are located in QUL_DIR/compatibility/QtQuickUltralite/* If the provided binaries don't match your project configuration, you can build the library with the desired settings.

The package contains a CMakeLists.txt file that builds the modules. To build the Extras module execute the QtQuickUltraliteExtras CMake target. The default output location is set to the CMAKE_BINARY_DIR CMake variable and can be changed by setting the QUL_COMPATIBILITY_MODULE_DIR CMake variable.

To automate the process you can https://cmake.org/cmake/help/latest/command/add_subdirectory.html of the CMakeLists.txt :

set(QUL_COMPATIBILITY_DIR ${Qul_DIR}/compatibility)
add_subdirectory(${QUL_COMPATIBILITY_DIR} ${CMAKE_BINARY_DIR}/compatibility)
							

Then add a dependency to your target:

add_dependencies(my_target QtQuickUltraliteExtras)
							

另请参阅 StaticText , ColorizedImage , ItemLayer , ImageLayer , SpriteLayer , 应用程序 ,和 Screen .