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,371
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTimer based Splash Screen

    Do you have an event loop running?

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

    Default Re: QTimer based Splash Screen

    Header File:
    Qt Code:
    1. #ifndef __INWAITSPLASH_H__
    2. #define __INWAITSPLASH_H__
    3.  
    4. #include "ui_INWaitSplash.h"
    5.  
    6. #define ROWSIZE 4
    7. #define COLUMNSIZE 4
    8. #define TAILLENGTH 4
    9.  
    10. class CINWaitSplash : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. CINWaitSplash(QWidget * parent = 0, Qt::WindowFlags f = Qt::SplashScreen|Qt::WindowStaysOnTopHint);
    16.  
    17. void Init();
    18. void Start();
    19. void Stop();
    20.  
    21. protected:
    22. void paintEvent(QPaintEvent *);
    23. void InitTable();
    24.  
    25. private slots:
    26. // Table Pattern Algorithms
    27. void FillTable_SnakePattern();
    28. //void FillTable_RandomPattern();
    29. //void FillTable_BoxPattern();
    30.  
    31. private:
    32. Ui::SplashForm ui;
    33.  
    34. QTimer* m_timerMain;
    35.  
    36. int m_aiCellTable[COLUMNSIZE][ROWSIZE];
    37. };
    38.  
    39. #endif
    To copy to clipboard, switch view to plain text mode 

    As for an event loop... I would have to say no because I am not sure what an event loop is. It is strange because if I turn the timers setInterval(100) to start(100) it will trigger... but after I run my Start() method from a function in my MainWindow it stops... and obviously stops on my Stop() method. So I know the connection is setup. I must be missing something fundamental.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,371
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.

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

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,371
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.