Splash screen image is not showing up



  • (I am new Qt user)

    I am figuring out how to display the Splash screen, and came upon this code https://qt-project.org/forums/viewreply/57388/. Code seems to work fine, but splash image (splash.png) is not showing up. Instead, I am getting completely black screen(that covers the entire screen) for 3 seconds, it disappears and shows the main window. I have added data.qrc with image directory. Running on Windows 7, 64 bit.

    Here is a warning it is giving me
    @Starting C:\Users\alex\Desktop\QT\build-Splash-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug\debug\Splash...
    QImage::scaled: Image is a null image
    C:\Users\alex\Desktop\QT\build-Splash-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug\debug\Splash exited with code 0@

    Thanks !
    @
    //main.cpp
    #include <QtCore>
    #include <QApplication>
    #include <QPixmap>
    #include <QSplashScreen>
    #include <QWidget>
    #include <QMainWindow>
    #include <QTimer>
    #include <QThread>
    #include <QDesktopWidget>
    #include <QPainter>

    int main(int argc, char* argv[])
    {
    QApplication app(argc, argv);
    QMainWindow* viewer = new QMainWindow();
    QImage splashScrImage (":/images/splash.png");
    QSize screenSize = QApplication::desktop()->geometry().size();
    QImage splashScr (screenSize, QImage::Format_ARGB32_Premultiplied);
    QPainter painter (&splashScr);
    painter.fillRect(splashScr.rect(), Qt::black);
    QImage scaled = splashScrImage.scaled(screenSize, Qt::KeepAspectRatio);
    QRect scaledRect = scaled.rect();
    scaledRect.moveCenter(splashScr.rect().center());
    painter.drawImage(scaledRect, scaled);
    QPixmap Logo;
    Logo.convertFromImage(splashScr);
    QSplashScreen splashScrWindow (viewer, Logo, Qt::WindowStaysOnTopHint);
    splashScrWindow.move(0,0);
    splashScrWindow.show();
    QTimer::singleShot(3000, &splashScrWindow ,SLOT(close()));
    viewer->show();
    return app.exec();
    }
    @

    data.qrc file
    @

    <RCC>
    <qresource prefix="/">
    <file>images/splash.png</file>
    </qresource>
    </RCC>@

    Splash.pro file
    @
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = Splash
    TEMPLATE = app

    SOURCES += main.cpp

    HEADERS +=

    FORMS +=

    RESOURCES +=
    data.qrc

    OTHER_FILES +=
    @



  • Works fine here

    The message "QImage::scaled: Image is a null image" implies that ":/images/splash.png" could not be loaded. Have you run qmake since you added data.qrc to the PRO file? Not a valid PNG perhaps?



  • +1
    [quote author="ChrisW67" date="1372302798"]Works fine here

    The message "QImage::scaled: Image is a null image" implies that ":/images/splash.png" could not be loaded. Have you run qmake since you added data.qrc to the PRO file? Not a valid PNG perhaps?

    [/quote]



  • [quote author="ChrisW67" date="1372302798"]Works fine here

    The message "QImage::scaled: Image is a null image" implies that ":/images/splash.png" could not be loaded. Have you run qmake since you added data.qrc to the PRO file? Not a valid PNG perhaps?

    [/quote]

    Indeed, it was my fault .........I didn't know that you had to run qmake. Was under impression that all I need is to run Build.
    Thanks !


  • Moderators

    [quote author="newprint" date="1372307299"]
    Indeed, it was my fault .........I didn't know that you had to run qmake. Was under impression that all I need is to run Build.
    Thanks ![/quote]
    just for clarification:
    qmake basically creates the makefiles for you (and a few things more) which are then built. Thus build command alone may not always work on always up to date makefiles.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.