Results 1 to 5 of 5

Thread: SLOT not being called

  1. #1
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default SLOT not being called

    Hi,

    I have the following code :

    Qt Code:
    1. m_pSliderMapper->setMapping( m_pSlider[0], 0 );
    2. connect( m_pSlider[0], SIGNAL(valueChanged(int)),m_pSliderMapper,SLOT(map()));
    3. connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int,int)) );
    To copy to clipboard, switch view to plain text mode 

    Where m_pSliderMapper is QSignalMapper and m_pSlider is QSlider. Can anyone see a reason why the ChangeTheTimer slot is not being called when I move the slider?

    Regards,
    Steve

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: SLOT not being called

    This is an incorrect signal slot connection
    Qt Code:
    1. connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int,int)) );
    To copy to clipboard, switch view to plain text mode 
    You can't connect a signal with one parameter to a slot with two parameters.

    With given information I can't be sure if this fits your problem, but perhaps you could work it around by giving the second parameter a default value:
    Qt Code:
    1. void ChangeTheTimer(int foo, int bar = 1234);
    To copy to clipboard, switch view to plain text mode 
    Then, drop the additional parameter from the connect-statement:
    Qt Code:
    1. connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int)) );
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: SLOT not being called

    Thanks as always JPN.

    I just use one parameter and get around it in the SLOT.

    Qt Code:
    1. m_pSliderMapper->setMapping( m_pSlider[0], 0 );
    2. connect( m_pSlider[0], SIGNAL(valueChanged(int)),m_pSliderMapper,SLOT(map()));
    3. connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int)) );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CSendMessage::ChangeTheTimer( int val)
    2. {
    3. if( m_pSlider[val] )
    4. {
    5. int value = m_pSlider[val]->value();
    6. if( m_pThread[val] )
    7. {
    8. m_pThread[val]->m_nTimer = value * 10;
    9. }
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Steve

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SLOT not being called

    How should this work:

    connect( m_pSlider[0], SIGNAL(valueChanged(int)),m_pSliderMapper,SLOT(map ()));
    ?

  5. #5
    Join Date
    Dec 2007
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: SLOT not being called

    Actually, if the slot has lesser number of parameters than the signal, Qt just ignores the remaining parameters. It is a perfectly valid scenario right? you are interested only in the event, but not values. but an invocation of a slot with more parameters than the signal would mean that the slot has to be invoked with invalid parameters (in theory) so Qt doesn't accept that. I guess it should have shown some printf about the 2nd conn being wrong at runtime!!!
    Let your work talk for you

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. connect() returns true but slot not called
    By OriginalCopy in forum Qt Programming
    Replies: 6
    Last Post: 4th November 2007, 18:54
  3. Replies: 2
    Last Post: 8th October 2007, 15:02
  4. Replies: 8
    Last Post: 1st May 2007, 22:35
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.