我的应用程序曾经在最新的美女更新之前工作,但不再工作了。启动画面仅在我将 init.qml 文件和 splashcreen.qml 文件上的 com.nokia.symbian 1.1 降级到 1.0 时才有效,但随后不显示 main.qml 文件。当我指示 main.cpp 直接加载 main.qml 时,应用程序确实可以工作...... 我迷路了!这是我为 main.cpp 提供的代码:
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.setSource(QUrl("qrc:/qml/SmartFlyer/init.qml"));
//viewer.setMainQmlFile(QLatin1String("qrc:qml/SmartFlyer/main.qml"));
viewer.showExpanded();
return app->exec();
}
对于 init.qml:
import QtQuick 1.1
import com.nokia.symbian 1.1
Item {
id: init
SplashScreen {
id: splash
show: true // show splash
minTimeout: 3000 // show splash at least for 3 sec
image: "data/splash_screen.png" // path to splash image
canFinish: false // change to true when main QML will be loaded
z: 100 // highest page.
}
Loader { // this component performs deferred loading.
id: mainLoader
onStatusChanged: {
if( mainLoader.status == Loader.Ready )
{
// main page is loaded
// time to hide splash
splash.canFinish = true
}
}
}
Component.onCompleted: {
// splash is already rendered on the screen
// user is looking on splash
// now we can start loader to load main page
mainLoader.source = "main.qml"
}
}
对于 splashscreen.qml :
import QtQuick 1.1
import com.nokia.symbian 1.1
Rectangle {
id: splash
anchors.fill: parent
color: "black"
property int minTimeout: 3000 // 3s by default.
property string image; // path to splash image
property bool show: false // if show is true then image opacity is 1.0, else 0.0
property bool canFinish: false // if true then we can hide spash after timeout
state: show ? "showingSplash" : ""
onStateChanged: {
if( state == "showingSplash" )
splashTimer.start();
}
opacity: 0.0
Image {
source: image
fillMode: Image.PreserveAspectFit
anchors.fill: parent
smooth: true
}
Timer {
id: splashTimer
interval: minTimeout
running: false
repeat: true
onTriggered: {
if( splash.canFinish )
{
// finally we can stop timer and hide splash
splash.show = false
splashTimer.repeat = false
}
else
{
// canFinish is false, but main.qml is not loaded yet
// we should run timer again and again
splashTimer.interval = 1000 // 1 sec
splashTimer.repeat = true
}
}
}
states: [
State {
name: "showingSplash"
PropertyChanges { target: splash; opacity: 1.0 }
}
]
// hide splash using animation
transitions: [
Transition {
from: ""; to: "showingSplash"
reversible: true
PropertyAnimation { property: "opacity"; duration: 500; }
}
]
}