Results 1 to 7 of 7

Thread: QTimer based Splash Screen

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTimer based Splash Screen

    What do you do after you call Start()? If you don't have an event loop running (either by calling QDialog::exec() or QApplication::exec() or reapeating QApplication:rocessEvents() calls) timers won't work.

  2. #2
    Join Date
    Aug 2006
    Posts
    90
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default Re: QTimer based Splash Screen

    Interesting...

    This is what I am doing.
    I have a class that contains a pointer to my MainWindow and my Splash Screen Widget.
    There I create a "singleton" instance of it that my class that can be used in my MainWindow's class. So inside a method of my MainWindow I am calling something like this:

    Qt Code:
    1. void CINMainWindow::Search()
    2. {
    3. INMyApp()->INWaitSplash()->Start();
    4. CINTimer::Sleep(1000); // Something meaningful would be done here
    5. INMyApp()->INWaitSplash()->Stop();
    6. }
    To copy to clipboard, switch view to plain text mode 

    So I am calling Start() and Stop() to my splash screen class from any where I want.

  3. #3
    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
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QTimer based Splash Screen

    It doesn't have any chance to work then. If you want to use timers, you have to call QApplication::exec() before or right after Start() and do the rest as small steps triggered by another timer with timeout set to 0, more or less like so:
    Qt Code:
    1. void MyClass::init1(){
    2. //...
    3. QTimer::singleShot(0, this, SLOT(init2()));
    4. }
    5.  
    6. void MyClass::init2(){
    7. //...
    8. QTimer::singleShot(0, this, SLOT(init3()));
    9. }
    10.  
    11. // ...
    12.  
    13. QTimer::singleShot(0, &MyObjectOfMyClass, SLOT(init1()));
    14. return app.exec();
    To copy to clipboard, switch view to plain text mode 

    Timers can only timeout() when the control is in the event loop, so having a single long operation won't allow them to be triggered as well. You either have to use QApplication:rocessEvents() or use 0-timeout timers like on the example above.

Similar Threads

  1. Problem with Splash Screen ?
    By vinod in forum Qt Programming
    Replies: 13
    Last Post: 11th April 2020, 17:15
  2. Replies: 3
    Last Post: 8th December 2006, 18:51

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.