【发布时间】:2020-09-16 08:50:49
【问题描述】:
我有一个用于 Linux 的嵌入式 Qt 应用程序,它具有以下启动代码:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Startup actions neeeded to display AppView correctly
// Black screen is shown for several seconds
// ...
QQuickView AppView;
AppView.setSource(QUrl(QStringLiteral("main.qml")));
AppView.resize(480, 800);
AppView.show();
return app.exec();
}
我想移除 AppView 之前显示的黑屏并显示 QML 动画 而不是它。
我在这里看到了两个可能的选项,但没有一个是明确的。能否请您指教 其中哪一个更正确,并评论/回答每个问题。
选项 1:在 main() 的开头显示 QSplashScreen。
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSplashScreen *splash = new QSplashScreen();
splash->show();
// Startup actions neeeded to display AppView correctly
// Black screen is shown for several seconds
// ...
}
这里的问题是使用什么 API 将 QML 动画附加到 QSplashScreen? QSplashScreen 继承自 QWidget,据我了解,不能使用像 QQuickWidget::setSource() 这样的 API。
选项 2:在 main() 的开头显示另一个 QQuickView 并附加 QML 动画。
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQuickView SplashView;
SplashView.setSource(QUrl(QStringLiteral("SplashScreen.qml")));
SplashView.resize(480, 800);
SplashView.show();
app.exec();
// Startup actions neeeded to display AppView correctly
// Black screen is shown for several seconds
// ...
QQuickView AppView;
AppView.setSource(QUrl(QStringLiteral("main.qml")));
AppView.resize(480, 800);
AppView.show();
}
这里的问题是如何关闭SplashView并在其上显示AppView?
谢谢
【问题讨论】:
-
AppView需要等待什么样的事情? -
一些应用程序启动代码,需要正确启动 AppView。
-
我之前做过闪屏,但 QQuickView 不是我需要等待的部分。一般的想法是尽可能快地显示一些东西,然后在应用程序的其余部分准备好时生成一个信号。如果可能的话,我会尝试重新做一些事情,以便应用程序可以在启动代码完成之前启动。
-
这里的代码很难改,因为它是一个已经存在的大应用程序。但我会努力,也许我会成功。感谢您的建议。