Results 1 to 4 of 4

Thread: Extending QTimer()

  1. #1
    Join Date
    Jan 2008
    Posts
    27
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Extending QTimer()

    Hi,

    I am trying to figure out how to extend the QTimer class so I can pass some variables through the timeout signal. Is that even possible? I was think I could like "catch" the normal timeout() emit and then just emit my own signal with some variables I need.

    Or is there some other way I am do not know of to pass arguments or at least get the QTimer object from the signal() that comes through?

    I have never done this before and pretty confused. Is what below anything similar to what it should be?

    Thanks

    Qt Code:
    1. #include <QTimer>
    2. #include "common.h"
    3.  
    4.  
    5. class FileTimer: public QTimer{
    6.  
    7. public:
    8. FileTimer(QObject * parent, uint16 dest, QString fileName):
    9. QTimer ( parent )
    10. {
    11. dest = dest;
    12. fileName = fileName;
    13. }
    14.  
    15. uint16 dest;
    16. QString fileName;
    17.  
    18. signals:
    19. void sendTimeout(uint16 dest, QString fileName);
    20.  
    21. void timeout()
    22. {
    23. emit QTimer::timeout();
    24. emit sendTimeout(dest, fileName);
    25. }
    26. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by rishid; 26th March 2008 at 17:01.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Extending QTimer()

    May be QSignalMapper can be of some help to you.

  3. #3
    Join Date
    Jun 2009
    Posts
    29
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Extending QTimer()

    But, after using a QSignalMapper how can I call a slot?
    For example:

    QTimer* timer = new QTimer(this);
    signalMapper = new QSignalMapper(this); //signalMapper is private to the class

    connect(timer,SIGNAL(timeout()),signalMapper,SLOT( map()));
    signalMapper->setMapping(this,index);
    connect(signalMapper,SIGNAL(mapped(int)),this,SIGN AL(timeout(int)));


    But, now How Can I connect to a function say crossCapture(int)?

    I tried connect(timer,SIGNAL(timeout()),this,crossCapture( int));
    and
    connect(timer,SIGNAL(timeout(int)),this,crossCaptu re(int));

    None of them works ..

  4. #4
    Join Date
    Jun 2009
    Posts
    29
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Extending QTimer()

    Sorry, My mistake:
    It should be like this to work perfectly:

    QTimer* timer = new QTimer(this);
    signalMapper = new QSignalMapper(this); //signalMapper is private to the class

    connect(timer,SIGNAL(timeout()),signalMapper,SLOT( map()));
    signalMapper->setMapping(timer,index);
    connect(signalMapper,SIGNAL(mapped(int)),this,SIGN AL(timeout(int)));

    connect(this,SIGNAL(timeout(int)),this,SLOT(crossCapture(int)));

    where timeout(int) is a signal of the current class.

Similar Threads

  1. Simple QTimer help
    By philips in forum Qt Programming
    Replies: 14
    Last Post: 6th July 2015, 08:39
  2. QThread/QObject and QTimer
    By swiety in forum Qt Programming
    Replies: 2
    Last Post: 25th January 2008, 08:37
  3. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 08:13
  4. Replies: 5
    Last Post: 6th March 2007, 05:34
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.