Results 1 to 8 of 8

Thread: QTimer QBasicTimer and QObject::startTimer

  1. #1
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Question QTimer QBasicTimer and QObject::startTimer

    QObject::startTimer(), what this QTimer or QBasicTimer? Why "Wyggly" example use QBasicTimer instead QObject::startTimer()?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTimer QBasicTimer and QObject::startTimer

    QBasicTimer is light-weight; there's no signals and slots involved like in QTimer. QBasicTimer is still a bit more convenient to use than startTimer().
    J-P Nurmi

  3. #3
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: QTimer QBasicTimer and QObject::startTimer

    Quote Originally Posted by jpn View Post
    QBasicTimer is light-weight; there's no signals and slots involved like in QTimer. QBasicTimer is still a bit more convenient to use than startTimer().
    This writing in docs, but i don't find where QObject::startTimer use QTimer and startTimer also use timerEvent, not signals.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTimer QBasicTimer and QObject::startTimer

    Quote Originally Posted by SABROG View Post
    This writing in docs, but i don't find where QObject::startTimer use QTimer and startTimer also use timerEvent, not signals.
    QObject::startTimer() doesn't use QTimer, but vice versa. QTimer uses QObject::startTimer() and informs timouts via signals. That's exactly what makes QTimer high-level and easy to use, but heavier than startTimer() or QBasicTimer.
    J-P Nurmi

  5. #5
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: QTimer QBasicTimer and QObject::startTimer

    QObject::startTimer() don't use QTimer or QBasicTimer:

    startTimer()->eventDispatcher->SetTimer() (winapi)

    so QObject::startTimer more lightweight than QTimer or QBasicTimer and i don't understand why QBasicTimer used in "Wyggly" example. May be this just don't good example.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTimer QBasicTimer and QObject::startTimer

    Quote Originally Posted by SABROG View Post
    QObject::startTimer() don't use QTimer or QBasicTimer:
    Isn't that what I just said?

    startTimer()->eventDispatcher->SetTimer() (winapi)

    so QObject::startTimer more lightweight than QTimer or QBasicTimer and i don't understand why QBasicTimer used in "Wyggly" example. May be this just don't good example.
    • QObject::startTimer() is the lowest-level timer available in Qt.
    • QBasicTimer brings more convenience, but it's basically the same than using QObject::startTimer() but more convenient.
    • QTimer is a high-level timer class. Very easy and convenient to use. Hides the timer events from the application developer. Just create a timer object, connect signals and slots, start the timer and you're done.
    • The Wyggle example was chosen to demonstrate the usage of QBasicTimer. Isn't it nice that there is at least some example using QBasicTimer? Most of them use QTimer instead, just like recommended by QBasicTimer docs.
    J-P Nurmi

  7. #7
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: QTimer QBasicTimer and QObject::startTimer

    Quote Originally Posted by jpn View Post
    Isn't that what I just said?
    Yes, i see your post after my reply. But this very strange:

    Qt Code:
    1. int QObject::startTimer(int interval)
    2. {
    3. Q_D(QObject);
    4. ...
    5. if (interval < 0) {
    6. qWarning("QObject::startTimer: QTimer cannot have a negative interval");
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Don't used, but talking about QTimer.

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTimer QBasicTimer and QObject::startTimer

    Quote Originally Posted by SABROG View Post
    Don't used, but talking about QTimer.
    Well, I admit that the comment looks peculiar at first sight, but it really makes sense because QObject::startTimer() is rarely used directly, but mostly via QTimer. Besides, this way the warning is fully understandable to both QObject::startTimer() and QTimer users, isn't it?
    J-P Nurmi

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.