如何在启动Qt/QML Android应用程序时立即显示启动画面?

4

我有一个空的 Qt/QML Android 应用,我想显示启动屏幕。

没有 启动屏幕实现,这些屏幕会被显示:

enter image description here

现在我正在按照此例子添加了启动屏幕到Android清单文件中。这是我得到的结果:

enter image description here

我的问题是,有没有可能避免屏幕1?我希望启动应用程序时立即显示启动屏幕。欢迎任何建议。提前致谢。

2个回答

3

感谢这篇文章,我认为我找到了解决这个问题的方法。

该文章作者针对 Qt/QML android 应用程序中闪屏界面的编写,写道:

基本上,你可以忽略任何仅使用 C++/QML 代码的解决方案。因为它们启动的太晚了。

我想补充一下,当作者说“它们启动太晚了”时,我认为这是因为所有的Qt/QML android应用程序在最后像.so(共享库)一样编译。所以当您的应用程序启动时,背后发生的事情是:

  1. 启动应用程序
  2. 加载共享库(您的Qt/QML Android应用程序)
  3. 从您的应用程序(共享库)中调用main()

现在解决方案以显示闪屏界面(详见上文文章):

  1. Create template from QtCreator for your android app if you don't have created yet.

  2. Create splash.xml inside android/res/drawable, like this

  3. Create custom theme, apptheme.xml inside android/res/values, like this

  4. Add this line in your activity tag in AndroidManifest.xmnl

    android:theme="@style/AppTheme"

  5. Also this line in AndroidManifest.xml, inside activity tag:

    <meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/splash"/>
    
  6. Now the rest is in your main.qml file. Set your Window/ApplicationWindow element as invisible at beginning(as I saw this will hold the splash screen), use Loader for your first page, and when its loaded, set the Window/ApplicationWIndow visible to true. This is my example:

Loader
{
    id: loader
    asynchronous: true
    anchors.fill: parent
    sourceComponent: MainScreen
    {
        width: root.width
        height: root.height

        Component.onCompleted:
        {
            root.isReady = true
        }
    }
}

2
在Qt5.15中,你可以在AndroidManifest.xml(在QtCreator中)选择一个Android本地启动画面图像。
另一种选择是使用简单快速的窗口启动你的软件:只有一个窗口、一个图像(异步)、一个计时器和一个加载器用于加载你软件的其余部分。
当计时器被激活(在1-2秒内),你可以开始加载器。

谢谢您的回答。我已经使用了QtCreator中的启动画面模板,但这并没有帮助解决问题。关于另一个选项,“启动软件...”,如果我理解正确的话,在我的main.qml文件中,我需要一个简单的图像作为启动画面,并且它将立即加载,其他“来自我的主要qml”的部分将被放置在Loader{}组件中,稍后再加载(使用计时器)。我是对的吗? - peco
是的,你说得对。想法是尽快启动闪屏 UI,然后使用 150 毫秒的计时器和加载器,动态加载真正的 UI。 - Miguel Angel Pons

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接