Results 1 to 5 of 5

Thread: QTimer Usage in C++ Unix / Windows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2017
    Posts
    3
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QTimer Usage in C++ Unix / Windows

    Hello everyone,

    This is a basic issue, but i didnt understand why I am failed timer slots. I used Qt 5.7 in console application timer isn't fired timeout signal.

    Qt Code:
    1. #include <QCoreApplication>
    2. #include "mytimer.h"
    3. #include <QThread>
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. MyTimer* myTimer = new MyTimer();
    9.  
    10. while(true)
    11. {
    12. QThread::yieldCurrentThread();
    13. }
    14.  
    15. return a.exec();
    16. }
    17.  
    18.  
    19. #ifndef MYTIMER_H
    20. #define MYTIMER_H
    21.  
    22. #include <QObject>
    23. #include <QTimer>
    24. class MyTimer : public QObject
    25. {
    26. Q_OBJECT
    27. public:
    28. explicit MyTimer(QObject *parent = 0);
    29. QTimer* timerObj;
    30. signals:
    31.  
    32. public slots:
    33. void TimerTick();
    34. };
    35.  
    36. #endif // MYTIMER_H
    37.  
    38. #include "mytimer.h"
    39. #include "iostream"
    40. MyTimer::MyTimer(QObject *parent) : QObject(parent)
    41. {
    42. timerObj = new QTimer(this);
    43. timerObj->setInterval(1000);
    44. connect(timerObj,SIGNAL(timeout()),this,SLOT(TimerTick()));
    45. timerObj->start();
    46. }
    47.  
    48. void MyTimer::TimerTick()
    49. {
    50. std::cout << "Timer Interrupt" << std::endl;
    51. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by rcanerA; 12th May 2017 at 20:13.

Similar Threads

  1. QPixmap/QImage serious issues between Windows/Unix
    By Largo in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2011, 13:22
  2. Border radius unix/windows
    By dacrawler in forum Newbie
    Replies: 2
    Last Post: 23rd January 2011, 13:27
  3. Emulating Unix on Windows
    By eichner in forum Qt Programming
    Replies: 5
    Last Post: 14th February 2008, 18:13
  4. distinguish windows and unix in Makefile
    By magland in forum General Programming
    Replies: 1
    Last Post: 4th April 2007, 19:43
  5. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00

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.