배포 할 때 모든 QML 파일에서 QtQuick x.y
문자열을 바꿨습니다. 소스 트리에 qml
폴더가 있고 빌드 트리에 동일한 qml
폴더를 갖고 싶으면 폴더를 배포 할 수 있지만 원하는 QtQuick 버전과 일치하도록 문자열을 바꿀 수 있습니다.
다음 솔루션은 POSIX 시스템에서 작동하지만 일부 명령 줄 도구가 필요합니다. Linux (Ubuntu)에서 테스트되었습니다. 어쩌면 Windows 명령 행에 대한 경험이있는 사람이 Windows 용 버전을 추가 할 수 있습니다.
당신의 .pro
에 추가 (다음 코드는 빌드 폴더 내에서, 소스 폴더 ../src/
에 도달 할 수 있다고 가정,이 경우는 ***
의견이 경로를 변경하지 않은 경우)
// Define QT5 macro for use in C++, and select the correct module for QML:
greaterThan(QT_MAJOR_VERSION, 4) {
DEFINES += QT5
QT += quick
} else {
QT += declarative
}
// Define qmake variables for QtQuick version, and if you want, QtQuick Controls:
equals(QT_MAJOR_VERSION, 4) {
equals(QT_MINOR_VERSION, 7) {
QT_QUICK_VERSION = 1.0
}
equals(QT_MINOR_VERSION, 8) {
QT_QUICK_VERSION = 1.1
}
}
equals(QT_MAJOR_VERSION, 5) {
QT_QUICK_VERSION = 2.$${QT_MINOR_VERSION}
equals(QT_MINOR_VERSION, 1): QT_QUICKCONTROLS_VERSION = 1.0
equals(QT_MINOR_VERSION, 2): QT_QUICKCONTROLS_VERSION = 1.1
equals(QT_MINOR_VERSION, 3): QT_QUICKCONTROLS_VERSION = 1.2
}
// Add a pre-build step which copies your qml folder
QtQuickVersion.target = FORCE
QtQuickVersion.commands = "rm -rf qml/;"
QtQuickVersion.commands += "cp -r ../src/qml/ .;" // <-- *** Here is the source path
!isEmpty(QT_QUICK_VERSION) {
QtQuickVersion.commands += "grep -rl 'QtQuick [0-9]\\.[0-9]' qml/ | xargs -r sed -i 's/QtQuick [0-9]\\.[0-9]/QtQuick $${QT_QUICK_VERSION}/g';"
}
!isEmpty(QT_QUICKCONTROLS_VERSION) {
QtQuickVersion.commands += "grep -rl 'QtQuick.Controls [0-9]\\.[0-9]' qml/ | xargs -r sed -i 's/QtQuick.Controls [0-9]\\.[0-9]/QtQuick.Controls $${QT_QUICKCONTROLS_VERSION}/g';"
}
// Give the Makefile target *any* name which will *not* be created
// as a file, so the step is always executed
PRE_TARGETDEPS += FORCE
QMAKE_EXTRA_TARGETS += QtQuickVersion
을 C에서
++ (main.cpp
), 당신은 Qt를 4 QDeclarativeView
다시 떨어지는 QQuickView
를 만들 수 있습니다
#ifdef QT5
#include <QGuiApplication>
#include <QQuickView>
#include <QQmlEngine>
#else
#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeEngine>
typedef QApplication QGuiApplication;
typedef QDeclarativeView QQuickView;
// The following is the official fallback for QStringLiteral,
// see qstring.h in Qt 5 after #ifndef QStringLiteral */
#define QStringLiteral(str) QString::fromUtf8("" str "", sizeof(str) - 1)
#endif
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
// (add qmlRegisterType etc.)
// Open the QML view with the main QML document:
QQuickView view;
view.setSource(QUrl::fromLocalFile(QStringLiteral("qml/main.qml")));
view.show();
// Needed for "Qt.quit()" within QML:
QObject::connect(view.engine(), SIGNAL(quit()), &a, SLOT(quit()));
// I normally use this sizing behavior:
view.setResizeMode(QQuickView::SizeRootObjectToView);
return a.exec();
}
qml/main.qml
다음과 같이 볼 수 위의 코드에 의해 연 QML 파일 다음 QML 파일이 적절한 QtQuick 버전을 선택합니다 가져 오기 지시문을 포함
// This import will replaced with the largest supported QtQuick version:
import QtQuick 1.0
Rectangle {
width: 450
height: 200
Text {
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
font.pointSize: Math.min(parent.width/10, parent.height/5)
// This text will also be replaced to show the correct QtQuick version:
text: "Hello from\nQtQuick 1.0!"
// Some fancy animations...
SequentialAnimation on scale {
running: true; loops: Animation.Infinite
NumberAnimation { from: 1; to: .6; easing.type: Easing.InOutQuad; duration: 600 }
NumberAnimation { from: .6; to: 1; easing.type: Easing.InOutQuad; duration: 600 }
}
SequentialAnimation on rotation {
running: true; loops: Animation.Infinite
NumberAnimation { from: -10; to: 10; easing.type: Easing.InOutQuad; duration: 2000 }
NumberAnimation { from: 10; to: -10; easing.type: Easing.InOutQuad; duration: 2000 }
}
}
MouseArea {
anchors.fill: parent
onClicked: Qt.quit()
}
}
(당신이 체크인 할 수 있습니다 빌드 폴더). Text
요소의 문자열도 대체되므로이 데모에서는 쉽게 버전을 볼 수 있습니다.