View Full Version : SLOT not being called
steg90
29th November 2007, 15:41
Hi,
I have the following code :
m_pSliderMapper->setMapping( m_pSlider[0], 0 );
connect( m_pSlider[0], SIGNAL(valueChanged(int)),m_pSliderMapper,SLOT(map ()));
connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int,i nt)) );
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
jpn
29th November 2007, 15:50
This is an incorrect signal slot connection
connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int,i nt)) );
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:
void ChangeTheTimer(int foo, int bar = 1234);
Then, drop the additional parameter from the connect-statement:
connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int)) );
steg90
29th November 2007, 16:21
Thanks as always JPN.
I just use one parameter and get around it in the SLOT.
m_pSliderMapper->setMapping( m_pSlider[0], 0 );
connect( m_pSlider[0], SIGNAL(valueChanged(int)),m_pSliderMapper,SLOT(map ()));
connect( m_pSliderMapper, SIGNAL(mapped(int)),this,SLOT(ChangeTheTimer(int)) );
void CSendMessage::ChangeTheTimer( int val)
{
if( m_pSlider[val] )
{
int value = m_pSlider[val]->value();
if( m_pThread[val] )
{
m_pThread[val]->m_nTimer = value * 10;
}
}
}
Regards,
Steve
ChristianEhrlicher
30th November 2007, 07:51
How should this work:
connect( m_pSlider[0], SIGNAL(valueChanged(int)),m_pSliderMapper,SLOT(map ()));
?
jogeshwarakundi
6th December 2007, 12:30
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!!!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.