June 25, 2012

Dakemz Dakemz
Lab Rat
3 posts

QML Splash Screen Not Working

 

My app used to work before the latest belle update but doesnt anymore. The splash screen only works when i downgrade com.nokia.symbian 1.1 to 1.0 on both the init.qml file and the splashcreen.qml file but then doesnt display the main.qml file. When I instruct main.cpp to directly load main.qml the app does work…. Im lost! Here is the code I have for main.cpp:

  1.  #include <QtGui/QApplication>
  2. #include "qmlapplicationviewer.h"
  3.  
  4. Q_DECL_EXPORT int main(int argc, char *argv[])
  5. {
  6.     QScopedPointer<QApplication> app(createApplication(argc, argv));
  7.  
  8.     QmlApplicationViewer viewer;
  9.     viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
  10.     viewer.setSource(QUrl("qrc:/qml/SmartFlyer/init.qml"));
  11.     //viewer.setMainQmlFile(QLatin1String("qrc:qml/SmartFlyer/main.qml"));
  12.     viewer.showExpanded();
  13.  
  14.     return app->exec();
  15. }

For init.qml:

  1. // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
  2. import QtQuick 1.1
  3. import com.nokia.symbian 1.1
  4.  
  5. Item {
  6.     id: init
  7.  
  8.     SplashScreen {
  9.         id: splash
  10.         show: true              // show splash
  11.         minTimeout: 3000         // show splash at least for 3 sec
  12.         image: "data/splash_screen.png"  // path to splash image
  13.         canFinish: false         // change to true when main QML will be loaded
  14.         z: 100                   // highest page.
  15.     }
  16.  
  17.     Loader { // this component performs deferred loading.
  18.         id: mainLoader
  19.         onStatusChanged: {
  20.             if( mainLoader.status == Loader.Ready )
  21.             {
  22.                 // main page is loaded
  23.                 // time to hide splash
  24.                 splash.canFinish = true
  25.             }
  26.         }
  27.     }
  28.  
  29.     Component.onCompleted:  {
  30.         // splash is already rendered on the screen
  31.         // user is looking on splash
  32.         // now we can start loader to load main page
  33.         mainLoader.source = "main.qml"
  34.     }
  35. }

And for splashscreen.qml :

  1. // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
  2. import QtQuick 1.1
  3. import com.nokia.symbian 1.1
  4.  
  5. Rectangle {
  6.     id: splash
  7.  
  8.     anchors.fill: parent
  9.     color: "black"
  10.  
  11.     property int minTimeout: 3000  // 3s by default.
  12.     property string image;            // path to splash image
  13.     property bool show: false       // if show is true then image opacity is 1.0, else 0.0
  14.  
  15.     property bool canFinish: false    // if true then we can hide spash after timeout
  16.  
  17.     state: show ? "showingSplash" : ""
  18.  
  19.     onStateChanged: {
  20.         if( state == "showingSplash" )
  21.             splashTimer.start();
  22.     }
  23.  
  24.     opacity: 0.0
  25.  
  26.     Image {
  27.         source: image
  28.         fillMode: Image.PreserveAspectFit
  29.         anchors.fill: parent
  30.         smooth: true
  31.     }
  32.  
  33.     Timer {
  34.         id: splashTimer
  35.         interval: minTimeout
  36.         running: false
  37.         repeat:  true
  38.         onTriggered: {
  39.             if( splash.canFinish )
  40.             {
  41.                 // finally we can stop timer and hide splash
  42.                 splash.show = false
  43.                 splashTimer.repeat = false
  44.             }
  45.             else
  46.             {
  47.                 // canFinish is false, but main.qml is not loaded yet
  48.                 // we should run timer again and again
  49.                 splashTimer.interval = 1000 // 1 sec
  50.                 splashTimer.repeat = true
  51.             }
  52.         }
  53.     }
  54.  
  55.     states: [
  56.         State {
  57.             name: "showingSplash"
  58.             PropertyChanges { target: splash;  opacity: 1.0 }
  59.         }
  60.     ]
  61.  
  62.     // hide splash using animation
  63.     transitions: [
  64.         Transition {
  65.             from: ""; to: "showingSplash"
  66.             reversible: true
  67.             PropertyAnimation { property: "opacity";  duration: 500; }
  68.         }
  69.     ]
  70. }

0 replies

 
  ‹‹ Is it better to work with Qt on embedded linux with X11 or with Wayland ?      Developing for 4.6.3 on eLinux with SDK 1.2 possible? ››

You must log in to post a reply. Not a member yet? Register here!