Qt:QtQuick:DECLARATIVE_EXAMPLE_MAIN 逃离我推掉我的手 2022-07-12 11:58 163阅读 0赞 ![这里写图片描述][SouthEast] 在官方示例工程里大多会看到这样的代码,没有main启动函数 #include "../../shared/shared.h" DECLARATIVE_EXAMPLE_MAIN(demos/stocqt/stocqt) 其实不是,DECLARATIVE\_EXAMPLE\_MAIN 封装了启动过程,看看这个宏定义 #include <QDir> #include <QGuiApplication> #include <QQmlEngine> #include <QQmlFileSelector> #include <QQuickView> //Not using QQmlApplicationEngine because many examples don't have a Window{} #define DECLARATIVE_EXAMPLE_MAIN(NAME) int main(int argc, char* argv[]) \ {\ QGuiApplication app(argc,argv);\ app.setOrganizationName("QtProject");\ app.setOrganizationDomain("qt-project.org");\ app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());\ QQuickView view;\ if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\ QSurfaceFormat f = view.format();\ f.setProfile(QSurfaceFormat::CoreProfile);\ f.setVersion(4, 4);\ view.setFormat(f);\ }\ view.connect(view.engine(), &QQmlEngine::quit, &app, &QCoreApplication::quit);\ new QQmlFileSelector(view.engine(), &view);\ view.setSource(QUrl("qrc:///" #NAME ".qml")); \ if (view.status() == QQuickView::Error)\ return -1;\ view.setResizeMode(QQuickView::SizeRootObjectToView);\ if (QGuiApplication::platformName() == QLatin1String("qnx") || \ QGuiApplication::platformName() == QLatin1String("eglfs")) {\ view.showFullScreen();\ } else {\ view.show();\ }\ return app.exec();\ } 可以看到里面就是一个完整的启动过程,qrc:///” \#NAME “.qml” 这段代码把demos/stocqt/stocqt组合为 qrc:///qmldemos/stocqt/stocqt.qml [SouthEast]: /images/20220710/5e33dc35aa1c45109dfd75b529cf5c4a.png
还没有评论,来说两句吧...