Results 1 to 20 of 21

Thread: emit a signal from inside a callback routine

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: emit a signal from inside a callback routine

    Hi. When I met the same problem I solved that with startTimer/killTimer and void timerEvent ( QTimerEvent * event ) reimplementation. Then what you can do is to set any Boolean variable (or QMutex based variable if you have multiple access) to true (lock) accordingly and process that inside timerEvent.

    Typical solution might be:

    Qt Code:
    1. static const int timeScale = 50; // 50 Msec
    2.  
    3. class A: public QObject
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8.  
    9. Q_INVOKABLE A( QObject * parent = 0 )
    10. : QObject(parent),
    11. m_check(false),
    12. m_timer(0)
    13. {
    14. m_timer = startTimer(timeScale);
    15. }
    16. ~A()
    17. {
    18. if (m_timer > 0)
    19. killTimer(m_timer);
    20. }
    21.  
    22. public slots:
    23.  
    24. void handler()
    25. {
    26. if (m_check)
    27. return;
    28. // do something here
    29. m_check = true;
    30. }
    31.  
    32. protected:
    33. void timerEvent ( QTimerEvent * event)
    34. {
    35. if (m_check)
    36. {
    37. // do something
    38. emit some_signal(some_args);
    39. m_check != m_check; // Just quicker
    40. }
    41. }
    42. private:
    43.  
    44. bool m_check;
    45. int m_timer;
    46. }
    To copy to clipboard, switch view to plain text mode 

    Good luck.
    Last edited by Tanuki-no Torigava; 8th December 2009 at 06:51.

Similar Threads

  1. how to emit signal in a static function ?
    By cxl2253 in forum Qt Programming
    Replies: 32
    Last Post: 7th July 2016, 22:36
  2. emit qt signal is very slow how it can be optimized?
    By sawerset in forum Qt Programming
    Replies: 8
    Last Post: 30th December 2008, 10:21
  3. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  4. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  5. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 15:26

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.