使用 qml+QQuickView 作为初始屏幕不起作用
Use qml+QQuickView as a splash screen NOT working
我想为我的 c++/qt/qml 应用程序添加一个启动画面。我添加了以下代码:
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;
}
和 Splash.qml 文件:
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
}
}
}
当应用程序启动时,消息:"qml:初始屏幕...打印了270 190 100x100",但QQuickWindow只是白色的。main.qml 的主窗口可以正常工作。我试图在 Splash.qml 中加载图像,但同样的问题。而且,我不能使用QQuickView::setWindowFlags将其设置为无框窗口。我正在研究win7 64位操作系统。
您可以在 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();
}
}
}
}
}
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- C++鼠标单击时的屏幕截图不起作用
- 使用 qml+QQuickView 作为初始屏幕不起作用
- glXCreateWindow在VISUAL_ID和屏幕>root_visual不相等时不起作用
- 在OpenGL屏幕中显示消息在Windows上不起作用