Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Splash screen image is not showing up
QtWS25 Last Chance

Splash screen image is not showing up

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    newprint
    wrote on last edited by
    #1

    (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 +=
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • N Offline
          N Offline
          newprint
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

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

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved