我有这个代码,我希望它显示一个闪屏,因为它会更大,已经制作了一种计时器,因此可以看到启动画面工作。问题是我没有看到启动画面,但代码将在启动画面不显示时运行,直接将我发送到主窗口而不显示splas屏幕。 这是我的代码。
的main.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();
}
splashwindow.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
命令的运行方式使得启动画面在运行之前不会出现,而不是显示,我无法找到解决方法。
[编辑]与闭包相对应的代码部分放错了位置,但在正确放置之后仍然无法正常工作。
答案 0 :(得分:3)
您至少有两个问题在进行:
#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();
}
TEMPLATE = app
TARGET = main
greaterThan(QT_MAJOR_VERSION, 4):QT += widgets
SOURCES += main.cpp
答案 1 :(得分:0)
什么对我有用, 最初在Qt的早期版本上有效的方法是在5.6版本上起作用,而从5.6版本开始就没有注释掉setWindowFlags语句。