首页 > 解决方案 > qml qt 5.12 在一个程序中使用模块 controls1 和 controls2

问题描述

我不能在一个程序中使用 QtQuick.Controls 1.2 和 QtQuick.Controls 2.12。尽管在 Qt 5.10 中这行得通。现在我在加载 main.qml 时收到此消息: “qrc:/MyButton.qml 2 module QtQuick.Controls 2.12 is not installed”

Qt 5.12。在 macOS 上构建 ios 或 ios 模拟器。

轮廓

QT += quick quickcontrols2
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
        main.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.qml

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Window {
    visible: true
    Button {
        id: button1
        text: "Controls 1 button"
        anchors.centerIn: parent
    }
    MyButton {
        text: "Controls 2 button"
        anchors {
            top: button1.bottom
            horizontalCenter: parent.horizontalCenter
        }
    }
}

我的按钮.qml

import QtQuick 2.9
import QtQuick.Controls 2.12
Button {
}

主文件

#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;
    return app.exec();
}

qml.qrc

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file>MyButton.qml</file>
    </qresource>
</RCC>

也许需要遵循一些限制或规则才能使其发挥作用?如果仅使用 Constools 1.2 或仅使用 Constols 2.12,则 main.qml 加载成功。

ps Build on windows for windows 和 build on windows for android 工作正常。问题仅在于 ios/ios 模拟器的 mac os 上构建。

标签: qtqmlqtquick2qtquickcontrols2qtquickcontrols

解决方案


推荐阅读