Qt popup screen not showing

I have this code, I want it to show the screen saver, because it will be larger by making a kind of timer so that you can see that the screen saver is working. The problem is that I do not see the splash screen, but the code will work until the splash screen appears, sending me directly to the main window without showing the splas screen. Here is my code.

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 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

The commands are launched in such a way that the splash screen will not be displayed before they are launched, and not shown, which I cannot find a way to fix.

[EDIT] The part of the code corresponding to the closure was inappropriate, although it still does not work after a proper installation.

+4
1

:

  • , . , while:

void QCoreApplication:: processEvents (QEventLoop:: ProcessEventsFlags flags = QEventLoop:: AllEvents) []

  • QSplashScreen , . . .

main.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
+3

All Articles