Minor tweaks.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-05-13 21:33:15 +08:00
parent d8e07b86c4
commit 083e5ec38c
1 changed files with 11 additions and 6 deletions

View File

@ -99,16 +99,21 @@ int main(int argc, char *argv[]) {
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0, qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0,
"FramelessHelper"); "FramelessHelper");
const QUrl url(QString::fromUtf8("qrc:///qml/main.qml")); const QUrl mainQmlUrl(QString::fromUtf8("qrc:///qml/main.qml"));
QObject::connect( const QMetaObject::Connection connection = QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &application, &engine, &QQmlApplicationEngine::objectCreated, &application,
[&url](QObject *obj, const QUrl &objUrl) { [&mainQmlUrl, &connection](QObject *object, const QUrl &url) {
if (!obj && (url == objUrl)) { if (url != mainQmlUrl) {
QCoreApplication::exit(-1); return;
}
if (!object) {
QGuiApplication::exit(-1);
} else {
QObject::disconnect(connection);
} }
}, },
Qt::QueuedConnection); Qt::QueuedConnection);
engine.load(url); engine.load(mainQmlUrl);
#endif #endif
return QApplication::exec(); return QApplication::exec();