[英]Qt Splash Screen not showing
我有這個代碼,我希望它顯示啟動畫面,因為它會更大,已經制作了一種計時器,因此可以看到啟動畫面正在工作。 問題是我沒有看到啟動畫面,但是當啟動畫面沒有出現時代碼將運行,直接將我發送到主窗口而不顯示啟動畫面。 這是我的代碼。
主程序
#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;
}
飛濺窗口.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
這些命令以這樣的方式運行,即在它們運行之前不會出現啟動畫面,不顯示,我找不到解決方法。
[編輯] 與閉包相對應的代碼部分放錯了位置,但正確放置后仍然無法正常工作。
您至少有兩個問題正在處理:
#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
對我有用的方法是在早期版本的 Qt 上運行,但從 5.6 開始就沒有了,那就是注釋掉 setWindowFlags 語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.