Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Splash screen image is not showing up

    General and Desktop
    4
    5
    3890
    Loading More Posts
    • 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
      newprint last edited by

      (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 Reply Quote 0
      • C
        ChrisW67 last edited by

        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 Reply Quote 0
        • D
          dbzhang800 last edited by

          +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 Reply Quote 0
          • N
            newprint last edited by

            [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 Reply Quote 0
            • raven-worx
              raven-worx Moderators last edited by

              [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 Reply Quote 0
              • First post
                Last post