現有兩種啓動Qt Quick App 模式:編程
qt默認使用第一種方法。app
QQmlApplicationEngine搭配Window:ui
1 #include <QGuiApplication> 2 #include <QQmlApplicationEngine> 3 4 int main(int argc, char *argv[]) 5 { 6 #if defined(Q_OS_WIN) 7 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 #endif 9 10 QGuiApplication app(argc, argv); 11 12 QQmlApplicationEngine engine; 13 engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 14 if (engine.rootObjects().isEmpty()) 15 return -1; 16 17 return app.exec(); 18 }
QQuickView搭配Item:spa
#include <QGuiApplication> #include <QQuickView> int main(int argc, char *argv[]) { #if defined(Q_OS_WIN) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQuickView viewer; viewer.setResizeMode(QQuickView::SizeRootObjectToView); viewer.setSource(QUrl("qrc:///main.qml")); viewer.show(); return app.exec(); }
——來自《Qt Quick核心編程》4.1.2code