Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the splash screen immediately when Qt/QML android app is launched?

I have empty Qt/QML android app and I am trying to display splash screen.

Without Splash screen implementation this screens are displayed:

enter image description here

Now I am following this example for splash screen which add the splash screen in the android manifest file. And this is the result I got:

enter image description here

My question is, Is it possible to avoid Screen number 1? Instead of screen 1, I want Splash screen to be displayed immediately when app is launched. Any suggestions are welcomed. Thanks in advance.

like image 625
peco Avatar asked Oct 27 '25 06:10

peco


2 Answers

I think I found a solution for this problem thanks to this post.

Author of that post, for splash screens in Qt/QML android app wrote:

Basically, you could ignore any solution by C++/QML code only. Because they are started late.

I would like to add that, when author said "they are started late", I think it is because all of your Qt/QML android app is compiled at the end like .so (shared library). So when your app start, what happens behind is:

  1. Launching the app
  2. Loading the shared library (your Qt/QML android app)
  3. Calling main() from your app (shared library)

Now the solution to display splash screen(Steps from the post above):

  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
        }
    }
}
like image 66
peco Avatar answered Oct 29 '25 22:10

peco


In Qt5.15 you can select a Android native splash screen image in AndroidManifest.xml (in QtCreator)

Other option is to start your software with a simple and fast window: just a window, a image (async), a timer, and a loader for the rest of your software.

When the timer is activated (within 1-2 seconds), you can start the loader.

like image 34
Miguel Angel Pons Avatar answered Oct 29 '25 22:10

Miguel Angel Pons