Results 1 to 3 of 3

Thread: QSplashScreen in a derived class from QApplication

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: QSplashScreen in a derived class from QApplication

    Good evening,
    I have an application where I derive from QApplication ( OBox is my class derived from QApplication ) and I have some problems with a QSplashScreen.

    Here I post some code:

    The main.cpp

    Qt Code:
    1. #include "OBox.h"
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. OBox application(argc, argv);
    6. return application.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    and here the ctor of OBox where I would show the QSplashScreen:

    Qt Code:
    1. #include "OBox.h"
    2.  
    3. #include <Windows.h>
    4. #include <Dbt.h>
    5.  
    6. #include <QDesktopServices>
    7. #include <QDateTime>
    8. #include <QInputDialog>
    9. #include <QProgressDialog>
    10. #include <QMessageBox>
    11. #include <QDebug>
    12. #include <QSplashScreen>
    13. #include <QPixmap>
    14.  
    15. #include "ReleaseVariables.h"
    16. #include "Utilities.h"
    17.  
    18. OBox::OBox(int& argc, char** argv) : QApplication(argc, argv)
    19. {
    20. // Initialize application info
    21.  
    22. setApplicationName(APPLICATION_TITLE);
    23. setApplicationVersion(APPLICATION_VERSION);
    24.  
    25. QSplashScreen *splash = new QSplashScreen;// <---- create a QSplashScreen
    26. splash->setPixmap(QPixmap(":/Resources/Splash.png"));// <----- set the image I would show
    27. splash->show();// <---- after show it close immediately
    28. qApp->processEvents();
    29.  
    30. // Initialize paths
    31.  
    32. m_applicationDir.setPath(QCoreApplication::applicationDirPath());
    33.  
    34. QString dataPath = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
    35. QDir dataDir(dataPath);
    36.  
    37. m_userDataDir.setPath(dataDir.filePath("OBoxUserData"));
    38. m_userDataDir.mkpath("."); // Make sure path exists (no problem if it's already there)
    39.  
    40. #ifndef DEVELOPMENT_MODE
    41.  
    42. QStringList libraryPaths;
    43.  
    44. if (m_applicationDir.exists("Plugins/Qt"))
    45. {
    46. libraryPaths.append(m_applicationDir.filePath("Plugins/Qt"));
    47. }
    48.  
    49. setLibraryPaths(libraryPaths);
    50.  
    51. #endif
    52.  
    53. setQuitOnLastWindowClosed(true);
    54.  
    55. // Initialize objects
    56.  
    57. m_drivesUpdateTimer = new QTimer(this);
    58. m_drivesUpdateTimer->setSingleShot(true);
    59.  
    60. connect(m_drivesUpdateTimer, SIGNAL(timeout()), SLOT(updateDrives()));
    61.  
    62. m_mainWindow = new MainWindow(this);
    63. m_mainWindow->showMaximized();
    64. QTimer::singleShot(15000, splash, SLOT(close()));// <------should close splash after 5s but doesn't have any effect
    65.  
    66. connect(this, SIGNAL(sourceDirPathsChanged(QStringList)),
    67. m_mainWindow, SLOT(setSourceDirPaths(QStringList)));
    68.  
    69. splash->finish(m_mainWindow);
    70. delete splash;
    71. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that the splashscreen close immediately without wait the close() slot that should be called by the timer ( 5s after the splashscreen creation).

    Where is the mystake(s) ?

    I hope to get help.

    Deleting the
    Qt Code:
    1. delete splash;
    To copy to clipboard, switch view to plain text mode 
    nothing changes.
    Seems the timer has no effect. I know that the event loop shold start to have a timer working.
    Regards
    Franco
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QSplashScreen in a derived class from QApplication

    You're calling finish() on the splash which closes the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default Re: QSplashScreen in a derived class from QApplication

    Thank you.
    The problem was on z order. The splashscreen wasn't on top.
    Adding a QWidget::raise () solved the problem.

    Regards,
    Franco
    Franco Amato

Similar Threads

  1. QwtPlot derived class
    By Marco Trapanese in forum Qwt
    Replies: 15
    Last Post: 4th December 2012, 11:05
  2. Replies: 3
    Last Post: 6th April 2012, 17:44
  3. Use QWidget derived class in Dialog
    By qtneuling in forum Qt Tools
    Replies: 2
    Last Post: 18th May 2008, 00:29
  4. rtti() of derived class
    By quickNitin in forum Newbie
    Replies: 4
    Last Post: 8th October 2006, 15:20
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 08:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.