Results 1 to 4 of 4

Thread: timeout() signal to a slot with arguments

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default timeout() signal to a slot with arguments

    Dear Friends

    I am trying to connect timeout() signal to a slot updateJobStatus(long ID), This updateJobStatus(long ID) should take an argument. If I dont put any argument in the function then its working fine. If I put arguments in the slot then its not working, check the code snippet below.

    int jobID=34343;
    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(updateJo bStatus(jobID)));
    timer->start(1000);

    Now this updateJobStatus basically displays the ID on a regular interval.

    But when I execute this program I can see
    Object::connect: No such slot MainWindow::updateJobStatus(jobID) in src/mainwindow.cpp:1903

    is it not possible to declare arguments in the solt. I am having some doubts in this
    Can anyone clear my doubts. Thanks in advance.sujan

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: timeout() signal to a slot with arguments

    Read about signal mappers

  3. #3
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: timeout() signal to a slot with arguments

    No, it is not possible to declare arguments in a slot using the connect function. For signals/slots, the argument list of the slot must be the same arguments or fewer than the signal. Otherwise, their isn't a value passed to the slot.

    Don't fret though, for your usage Qt DOES have a way around this though using the class QSignalMapper.

    Good luck!
    Amos
    Qt Programmer Extraordinaire

    Current Work:
    Ripxx Sports Measurement Device - www.ripxx.com
    (Featured in MYTHBUSTERS on 2010-05-19 in S08E08)

  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: timeout() signal to a slot with arguments

    You can use 3-rd party classes, such as libqxt's QxtTimer

Similar Threads

  1. slot with variable arguments
    By kung-foo in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2009, 19:24
  2. Replies: 2
    Last Post: 9th September 2009, 00:26
  3. Can we connect QTimer::SingleShot with a slot taking arguments?
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2008, 18:02
  4. passing arguments in SLOT
    By eleanor in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2008, 21:55
  5. Calling a slot with arguments
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 1st May 2008, 21:22

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.