PDA

View Full Version : signal / slot problem



franco.amato
4th December 2009, 19:40
Hi I have the setCurrentTime() slot in my class::QWidges so:

class WaveWidget : public QWidget
{
Q_OBJECT

public:
WaveWidget( QWidget* parent = 0 );
void setSoundFile( QString soundName_ );
void setWave( SoundData* );
void playSound();
qreal currentTime() const;

public slots:
void setCurrentTime();// <---- THIS ONE

protected:
/* paint event */
virtual void paintEvent( QPaintEvent* event );
/* resize event */
virtual void resizeEvent ( QResizeEvent* event );
/* mouse events */
virtual void mousePressEvent( QMouseEvent* event );
virtual void mouseMoveEvent( QMouseEvent* event );
virtual void mouseReleaseEvent( QMouseEvent* event );
virtual void keyPressEvent( QKeyEvent* event );

private:
void updateWave();

//QPixmap m_waveCachePixmap;
QImage m_waveCachePixmap;
SoundData* m_wave;

/* starting point of selection */
QPoint startSelection;
/* rubberBand */
WfRubberBand* rb;
/* current position of timeline */
qreal m_CurrentTime;
QTimer* timer;
};

In the ctor I connect it with the timeout signal of a timer so:

WaveWidget::WaveWidget( QWidget* parent /* = 0 */ )
: QWidget( parent ),
m_wave( 0 ),
rb( 0 )
{
setFocusPolicy( Qt::TabFocus );
timer = new QTimer();

connect( timer, SIGNAL( timeout() ), this, SLOT( setCurrentTime() ) );
}

and the slot code is so:

void WaveWidget::setCurrentTime()
{
static int i = 0;
qDebug() << i++; // only for test
}

The compile process is OK meanwhile when I run the app I always get a console error:

QObject::connect: No such slot WaveWidget::setCurrentTime()

Where my cose is wrong?

Help me please,
Best

wysota
4th December 2009, 19:43
Try running make clean, qmake and make again.

Lykurg
4th December 2009, 19:44
I guess you added the slot later, so please make a complete "make clean" on your directory and rebuild your application. Then all should work fine.


Edit: Damn, too late:D

franco.amato
4th December 2009, 20:33
Try running make clean, qmake and make again.

I work with visual studio under windows

franco.amato
4th December 2009, 20:39
I guess you added the slot later, so please make a complete "make clean" on your directory and rebuild your application. Then all should work fine.


Edit: Damn, too late:D

I gave clean, rebuild all under visual studio and it still doesn't work.

Lykurg
4th December 2009, 20:39
I work with visual studio under windows
And? Then clean manually all generated files *.o moc files etc. and rebuild.

franco.amato
4th December 2009, 20:42
I again rebuilded and now I didn't get the error but the code of the slot is not executed

wysota
4th December 2009, 20:48
Did you tell your visual studio to run moc on the header file and compile code generated by it?

franco.amato
4th December 2009, 20:53
Did you tell your visual studio to run moc on the header file and compile code generated by it?

Yes I have custom rules on the .h file and I link the generated .cpp file...
I can not see at console the qDebug output

Lykurg
4th December 2009, 20:58
I can not see at console the qDebug output

That's because you didn't start the timer?

franco.amato
4th December 2009, 21:07
That's because you didn't start the timer?

Yes I start the timer when I press space so:


/************************************************** **********************/
/* key press event */
/************************************************** **********************/
void WaveWidget::keyPressEvent( QKeyEvent* pe )
{
if(!m_wave)
{
qDebug("Sound not loaded");
pe->ignore();
return;
}

switch( pe->key() )
{
case Qt::Key_P:
{
// pause/unpause the sound
pe->accept();
bool playing;
m_wave->getCurrentChannel()->isPlaying( &playing );
if(playing == false)
{
qDebug("Sound loaded but channel not ready");
break;
}
else
{
bool paused;
m_wave->getCurrentChannel()->getPaused( &paused );
m_wave->getCurrentChannel()->setPaused( !paused );
}

break;
}
case Qt::Key_Space:
{
pe->accept();
m_wave->playSound( 0, 0 );
break;
}
default:
QWidget::keyPressEvent(pe);
break;
}
}

and


void WaveWidget::playSound()
{
qDebug() << "something";
m_wave->playSound( 0, 0 );
timer->start(100);
}

The strange thing is that I can not see the output of qDebug in the playSound. Seems disabled

franco.amato
4th December 2009, 21:17
I discovered the error. Was my mistake.

Thank you

Lykurg
4th December 2009, 21:17
Yes I start the timer when I press space so:
[...]
The strange thing is that I can not see the output of qDebug in the playSound. Seems disabled
You don't start the timer! Because you don't call startSound of you widget, you are calling the function of m_wave! That are two different functions!

franco.amato
8th December 2009, 18:10
You don't start the timer! Because you don't call startSound of you widget, you are calling the function of m_wave! That are two different functions!

Yes you're right.
Thank you Lykurg I solved it.

Best