Qt 初始屏幕未显示
Qt Splash Screen not showing
我有这段代码,我希望它显示一个启动画面,因为它会更大,已经制作了一种计时器,所以可以看到启动画面工作。问题是我没有看到初始屏幕,但是代码将在初始屏幕未出现时运行,将我直接发送到主窗口而不显示 splas 屏幕。这是我的代码。
主.cpp
#include <iostream>
#include <QApplication>
#include <quazip/quazip.h>
#include "splashwindow.h"
#include "mainwindow.h"
#include "database.h"
int main(int argc, char *argv[])
{
/* Define the app */
QApplication app(argc, argv);
/* Define the splash screen */
SplashWindow splashW;
/* Show the splash screen */
splashW.show();
/* Download the database */
/* Define the database */
Downloader db;
/* Donwloading the database */
db.doDownload();
/* Unzip the database */
/* Define the database */
//Unzipper uz;
//uz.Unzip();
for(int i = 0; i < 1000000; i++)
{
cout << i << endl;
}
/* Close the splash screen */
splashW.hide();
splashW.close();
/* Define the main screen */
MainWindow mainW;
/* Show the main window */
mainW.showMaximized();
return app.exec();
}
闪光窗口.cpp
#include <iostream>
#include <QStyle>
#include <QDesktopWidget>
#include "splashwindow.h"
#include "ui_splashwindow.h"
#include "database.h"
/* Splash screen constructor */
SplashWindow::SplashWindow (QWidget *parent) :
QMainWindow(parent), ui(new Ui::SplashWindow)
{
ui->setupUi(this);
/* Set window's flags as needed for a splash screen */
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::SplashScreen);
}
/* Splash screen destructor */
SplashWindow::~SplashWindow()
{
delete ui;
}
Splashwindow.h
#ifndef SPLASHWINDOW_H
#define SPLASHWINDOW_H
#include <QMainWindow>
namespace Ui {
class SplashWindow;
}
class SplashWindow : public QMainWindow
{
Q_OBJECT
public:
explicit SplashWindow(QWidget *parent = 0);
~SplashWindow();
private:
Ui::SplashWindow *ui;
};
#endif // SPLASHWINDOW_H
命令以这样的方式运行,即在运行之前不会显示初始屏幕,不显示,我找不到修复方法。
[编辑] 与闭包对应的代码部分放错了位置,尽管正确放置后仍然不起作用。
您至少有两个问题正在进行中:
- 您将主线程发送到阻塞循环中,它无法处理包括窗口显示在内的事件。这需要一些事件处理,因此您需要在 while 循环之前调用以下方法:
void QCoreApplication::p rocessEvents(QEventLoop::P rocessEventsFlags flags = QEventLoop::AllEvents) [static]
- 我建议根据文档在第一个中使用QSplashScreen。请注意示例中对处理事件的显式调用。下面的代码对我来说效果很好。
主.cpp
#include <QApplication>
#include <QPixmap>
#include <QMainWindow>
#include <QSplashScreen>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("splash.png");
QSplashScreen splash(pixmap);
splash.show();
app.processEvents();
for (int i = 0; i < 500000; ++i)
qDebug() << i;
QMainWindow window;
window.show();
splash.finish(&window);
return app.exec();
}
main.pro
TEMPLATE = app
TARGET = main
greaterThan(QT_MAJOR_VERSION, 4):QT += widgets
SOURCES += main.cpp
什么对我有用,在Qt的早期版本上工作,但自5.6以来不是注释掉setWindowFlags语句的地方。
相关文章:
- Winapi:屏幕截图未显示在窗口中
- 如何在快板的屏幕中显示子位图的绘制?
- SFML 中的字体.信息不显示在屏幕上.显示的不是信息,而是点
- 如何使用 openGL 在屏幕上显示加载的纹理
- 如何使用方法覆盖在输出屏幕上显示堆栈整数值
- 如何使用TouchGFX在LCD屏幕上显示ADC值
- 为什么屏幕上显示了一半的三角形
- 如何在屏幕上显示对象列表?
- C++列出屏幕以在第二台显示器中显示图像
- 显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题
- 将25个甚至整数存储到一个名为intlist的整数阵列中,然后在屏幕上显示数组,并在屏幕上显示名为fivintegers
- QML强制窗口将在第一个屏幕上显示
- 如何使用OpenGL在屏幕上显示三角形
- 从文本文件中读取行并显示在屏幕上
- 我的程序没有将字符显示在屏幕上
- 在屏幕上显示矢量
- 在同一屏幕上显示两个不同的对象
- 屏幕显示脚本中'.'令牌之前的预期非限定 id
- C / SFML:使用两个递归调用在屏幕上打印凸形形状仅显示第一个递归调用中的形状,而不是第二个
- 如果我使用的是迭代器,为什么在c++中没有屏幕显示呢