Qt QML启动屏幕不工作
我的应用程序在最新的belle更新之前就可以运行了,但现在不行了。仅当我将init.qml文件和splashscreen.qml文件的com.nokia.symbian 1.1降级为1.0时,启动屏幕才起作用,但随后不显示main.qml文件。当我指示main.cpp直接加载main.qml时,应用程序确实可以工作…。我迷路了!以下是main.cpp的代码:Qt QML启动屏幕不工作,qt,splash-screen,qml,Qt,Splash Screen,Qml,我的应用程序在最新的belle更新之前就可以运行了,但现在不行了。仅当我将init.qml文件和splashscreen.qml文件的com.nokia.symbian 1.1降级为1.0时,启动屏幕才起作用,但随后不显示main.qml文件。当我指示main.cpp直接加载main.qml时,应用程序确实可以工作…。我迷路了!以下是main.cpp的代码: #include <QtGui/QApplication> #include "qmlapplicationvie
#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();
}
对于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; }
}
]
}
至于我,我用一种“老派”的方式来显示Splash,没有任何QML。在这里,您可以看到如何在渐变背景上放置图像徽标:
QSplashScreen *Application::buildSplashScreen() {
const QPixmap logoPixmap(":/images/logo.png");
QDesktopWidget *desktop = QApplication::desktop();
QRect desktopRect = desktop->availableGeometry();
QPixmap splashPixmap(desktopRect.width(), desktopRect.height());
QPainter painter;
painter.begin(&splashPixmap);
QLinearGradient backgroundGradient(splashPixmap.rect().width() / 2,
0,
splashPixmap.rect().width() / 2,
splashPixmap.rect().height());
backgroundGradient.setColorAt(0, QColor::fromRgb(40, 50, 57));
backgroundGradient.setColorAt(1, QColor::fromRgb(19, 25, 29));
painter.fillRect(splashPixmap.rect(), backgroundGradient);
QRect logoRect((splashPixmap.width() - logoPixmap.width()) / 2,
(splashPixmap.height() - logoPixmap.height()) / 2,
logoPixmap.width(),
logoPixmap.height());
painter.drawPixmap(logoRect, logoPixmap);
painter.end();
QScopedPointer<QSplashScreen> splashScreen(new QSplashScreen(splashPixmap));
if (desktopRect.width() > desktopRect.height()) {
splashScreen->setAttribute(Qt::WA_LockLandscapeOrientation, true);
} else {
splashScreen->setAttribute(Qt::WA_LockPortraitOrientation, true);
}
return splashScreen.take();
}
qsplashsscreen*应用程序::buildSplashScreen(){
const QPixmap logoPixmap(“:/images/logo.png”);
QDesktopWidget*desktop=QApplication::desktop();
QRect desktopRect=desktop->availableGeometry();
QPixmap splashPixmap(desktopRect.width(),desktopRect.height());
油漆工;
绘制。开始(&splashPixmap);
QlineArgent背景渐变(splashPixmap.rect().width()/2,
0,
splashPixmap.rect().width()/2,
splashPixmap.rect().height();
背景梯度:setColorAt(0,QColor::fromRgb(40,50,57));
背景梯度:setColorAt(1,QColor::fromRgb(19,25,29));
painter.fillRect(splashPixmap.rect(),backgroundGradient);
QRect logoRect((splashPixmap.width()-logoPixmap.width())/2,
(splashPixmap.height()-logoPixmap.height())/2,
logoPixmap.width(),
logoPixmap.height());
painter.drawPixmap(logoRect,logoPixmap);
结束();
QScopedPointer splashScreen(新QSplashScreen(splashPixmap));
if(desktopRect.width()>desktopRect.height()){
splashScreen->setAttribute(Qt::WA_LockLandscapeOrientation,true);
}否则{
splashScreen->setAttribute(Qt::WA_方向,真);
}
返回splashScreen.take();
}
然后,我在程序启动时使用手动构建的飞溅:
int Application::run() {
QScopedPointer<QSplashScreen> splashScreen(buildSplashScreen());
splashScreen->showFullScreen();
QScopedPointer<QDeclarativeView> applicationWindow(buildRootView());
splashScreen->finish(applicationWindow.data());
applicationWindow->showFullScreen();
return QApplication::exec();
}
int应用程序::run(){
QScopedPointer splashScreen(buildSplashScreen());
splashScreen->showFullScreen();
QScopedPointer应用程序窗口(buildRootView());
splashScreen->finish(applicationWindow.data());
应用程序窗口->显示全屏();
返回QApplication::exec();
}
int Application::run() {
QScopedPointer<QSplashScreen> splashScreen(buildSplashScreen());
splashScreen->showFullScreen();
QScopedPointer<QDeclarativeView> applicationWindow(buildRootView());
splashScreen->finish(applicationWindow.data());
applicationWindow->showFullScreen();
return QApplication::exec();
}