I want to add a splash screen to my c++/qt/qml applicaiton. I added the following codes:
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QQuickView *view = new QQuickView;
view->setSource(QUrl(QLatin1String("qrc:/Splash.qml")));
view->show();
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
view->close();
app.exec();
return 0;
}
And the Splash.qml file:
import QtQuick 2.0
import QtQuick.Controls 2.1
Item {
visible: true
width: 640
height: 480
BusyIndicator {
anchors.centerIn: parent
width: 100
height: 100
running: true
Component.onCompleted: {
console.log("splash screen... " + x + " " + y + " " + width + "x" + height)
visible=true
}
}
}
When the application was starting, the message:"qml: splash screen... 270 190 100x100" was printed, but the QQuickWindow is just in white color. The main window for main.qml can work correctly. I tried to load an image in the Splash.qml,but same problem. And, I can NOT make it to be a frameless window using QQuickView::setWindowFlags. I'm working on win7 64bits OS.
You can do that easy in QML:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Window 2.0
Window {
id: mainWindow
width: 600
height: 400
visible: false
x: Screen.width / 2 - width / 2;
y: Screen.height / 2 - height / 2;
Window {
id: splashWindow
width: 300
height: 200
visible: true
x: Screen.width / 2 - width / 2;
y: Screen.height / 2 - height / 2;
flags: Qt.SplashScreen;
Rectangle {
anchors.fill: parent
color: "green";
}
ProgressBar {
id: progressBar
anchors.centerIn: parent
anchors.margins: 20
value: 0.01
}
Timer {
id: timer
interval: 50
repeat: true
running: true
onTriggered: {
progressBar.value += 0.01
if(progressBar.value >= 1.0) {
timer.stop();
mainWindow.visible = true;
splashWindow.destroy();
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.