Results 1 to 20 of 48

Thread: Multiple timers in single Application

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #18
    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: Multiple timers in single Application

    Quote Originally Posted by mahi6a1985 View Post
    Dear then suggest me one example with 6 timers with different slots with different timers and they should run at a time.
    It's not a problem to have six timers and execute them in time. It's a problem when you are trying to do more than your machine can handle.

    Here is a simple example that shows that you can have six timers in an app:

    Qt Code:
    1. #include <QtCore>
    2.  
    3. class Dummy : public QObject {
    4. Q_OBJECT
    5. public:
    6. Dummy(){}
    7. public slots:
    8. void timeout() {
    9. QTimer *timer = qobject_cast<QTimer*>(sender());
    10. if(!timer) return;
    11. qDebug() << "Now is" << QDateTime::currentDateTime() << "timer id:" << timer->property("timerId").toInt() << ", interval is" << timer->interval() << "ms";
    12. }
    13. };
    14.  
    15. #include "main.moc"
    16.  
    17. int main(int argc, char **argv) {
    18. QCoreApplication app(argc, argv);
    19. Dummy d;
    20. for(int i=0;i<6;++i) {
    21. QTimer *timer = new QTimer(&app);
    22. timer->setInterval(50+(qrand() % 200));
    23. timer->setProperty("timerId", i);
    24. QObject::connect(timer, SIGNAL(timeout()), &d, SLOT(timeout()));
    25. timer->start();
    26. }
    27. return app.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

    The main concept of my app is through tcp/ip client - server App. in which my app is client & which always sends 1 telegram every 100ms using "update_HmiScrLvl4".

    and the telegram construction & values will produced by the other timers, so dat the constructed telegram can be sent to server using "update_HmiScrLvl4".
    You don't need any threads for that nor any (not a single one!) timers. You just need to use QTcpSocket properly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    mahi6a1985 (24th September 2012)

Similar Threads

  1. Single Application Instance
    By BadKnees in forum Qt Programming
    Replies: 8
    Last Post: 4th November 2014, 14:57
  2. Multiple project files in a single directory
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 17th July 2008, 07:03
  3. Single QGLContext across multiple QGLWidgets
    By pseudosig in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2008, 23:13
  4. Single slot for multiple list boxes
    By Sheetal in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2008, 06:53
  5. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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.