Results 1 to 5 of 5

Thread: Problem with QTimer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Problem with QTimer

    This is what I wrote to make a simple timer.
    openSuse 11, Qt 4.5, Qt Creator, Qt GUI App

    It doesn't work, I mean when I try to execute it "Hi" doesn't appear on Konsole. I tried to debug it in the constructor of the class, but gdb never goes there.
    Thanks for your help

    MyObject.h
    Qt Code:
    1. #include <QtCore/QObject>
    2. #include <QtCore/QTimer>
    3. class MyObject : public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. MyObject();
    8. private:
    9. QTimer *timer;
    10.  
    11. private slots:
    12. void timerEvent();
    13. };
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. MyObject::MyObject()
    2. {
    3. timer = new QTimer(this);
    4. connect(timer, SIGNAL(timeout()), this, SLOT(timerEvent()));
    5. timer->setInterval(10);
    6. timer->start();
    7. }
    8.  
    9. void MyObject::timerEvent()
    10. {
    11. std::cout << "Hi" << std::endl;
    12. timer->start();
    13. }
    14.  
    15. int main()
    16. {
    17. MyObject mo;
    18. sleep(5);
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 11th April 2009 at 23:32.

Similar Threads

  1. Problem with operating of QTimer
    By sudheer168 in forum Newbie
    Replies: 3
    Last Post: 8th October 2008, 20:58
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  3. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 16:50
  4. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 08:13
  5. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54

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.