我不能在一个程序中使用QtQuick.Controls 1.2和QtQuick.Controls 2.12。尽管在Qt 5.10中有效。现在,我在加载main.qml时收到此消息: “未安装qrc:/MyButton.qml 2模块QtQuick.Controls 2.12”
Qt 5.12。在适用于ios或ios模拟器的macOS上构建。
专业文件
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
}
}
}
MyButton.qml
import QtQuick 2.9
import QtQuick.Controls 2.12
Button {
}
main.cpp
#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成功加载。
p.s。在Windows的Windows上构建和在Android的Windows上构建都可以正常工作。问题仅在于在Mac OS上针对ios / ios模拟器进行构建。