Results 1 to 14 of 14

Thread: signal / slot problem

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default signal / slot problem

    Hi I have the setCurrentTime() slot in my class::QWidges so:
    Qt Code:
    1. class WaveWidget : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. WaveWidget( QWidget* parent = 0 );
    7. void setSoundFile( QString soundName_ );
    8. void setWave( SoundData* );
    9. void playSound();
    10. qreal currentTime() const;
    11.  
    12. public slots:
    13. void setCurrentTime();// <---- THIS ONE
    14.  
    15. protected:
    16. /* paint event */
    17. virtual void paintEvent( QPaintEvent* event );
    18. /* resize event */
    19. virtual void resizeEvent ( QResizeEvent* event );
    20. /* mouse events */
    21. virtual void mousePressEvent( QMouseEvent* event );
    22. virtual void mouseMoveEvent( QMouseEvent* event );
    23. virtual void mouseReleaseEvent( QMouseEvent* event );
    24. virtual void keyPressEvent( QKeyEvent* event );
    25.  
    26. private:
    27. void updateWave();
    28.  
    29. //QPixmap m_waveCachePixmap;
    30. QImage m_waveCachePixmap;
    31. SoundData* m_wave;
    32.  
    33. /* starting point of selection */
    34. QPoint startSelection;
    35. /* rubberBand */
    36. WfRubberBand* rb;
    37. /* current position of timeline */
    38. qreal m_CurrentTime;
    39. QTimer* timer;
    40. };
    To copy to clipboard, switch view to plain text mode 

    In the ctor I connect it with the timeout signal of a timer so:
    Qt Code:
    1. WaveWidget::WaveWidget( QWidget* parent /* = 0 */ )
    2. : QWidget( parent ),
    3. m_wave( 0 ),
    4. rb( 0 )
    5. {
    6. setFocusPolicy( Qt::TabFocus );
    7. timer = new QTimer();
    8.  
    9. connect( timer, SIGNAL( timeout() ), this, SLOT( setCurrentTime() ) );
    10. }
    To copy to clipboard, switch view to plain text mode 

    and the slot code is so:
    Qt Code:
    1. void WaveWidget::setCurrentTime()
    2. {
    3. static int i = 0;
    4. qDebug() << i++; // only for test
    5. }
    To copy to clipboard, switch view to plain text mode 

    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
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: signal / slot problem

    Try running make clean, qmake and make again.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: signal / slot problem

    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

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    Quote Originally Posted by wysota View Post
    Try running make clean, qmake and make again.
    I work with visual studio under windows
    Franco Amato

  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    Quote Originally Posted by Lykurg View Post
    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
    I gave clean, rebuild all under visual studio and it still doesn't work.
    Franco Amato

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: signal / slot problem

    Quote Originally Posted by franco.amato View Post
    I work with visual studio under windows
    And? Then clean manually all generated files *.o moc files etc. and rebuild.

  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    I again rebuilded and now I didn't get the error but the code of the slot is not executed
    Franco Amato

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: signal / slot problem

    Did you tell your visual studio to run moc on the header file and compile code generated by it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    Quote Originally Posted by wysota View Post
    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
    Franco Amato

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: signal / slot problem

    Quote Originally Posted by franco.amato View Post
    I can not see at console the qDebug output
    That's because you didn't start the timer?

  11. #11
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    Quote Originally Posted by Lykurg View Post
    That's because you didn't start the timer?
    Yes I start the timer when I press space so:

    Qt Code:
    1. /************************************************************************/
    2. /* key press event */
    3. /************************************************************************/
    4. void WaveWidget::keyPressEvent( QKeyEvent* pe )
    5. {
    6. if(!m_wave)
    7. {
    8. qDebug("Sound not loaded");
    9. pe->ignore();
    10. return;
    11. }
    12.  
    13. switch( pe->key() )
    14. {
    15. case Qt::Key_P:
    16. {
    17. // pause/unpause the sound
    18. pe->accept();
    19. bool playing;
    20. m_wave->getCurrentChannel()->isPlaying( &playing );
    21. if(playing == false)
    22. {
    23. qDebug("Sound loaded but channel not ready");
    24. break;
    25. }
    26. else
    27. {
    28. bool paused;
    29. m_wave->getCurrentChannel()->getPaused( &paused );
    30. m_wave->getCurrentChannel()->setPaused( !paused );
    31. }
    32.  
    33. break;
    34. }
    35. case Qt::Key_Space:
    36. {
    37. pe->accept();
    38. m_wave->playSound( 0, 0 );
    39. break;
    40. }
    41. default:
    42. QWidget::keyPressEvent(pe);
    43. break;
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. void WaveWidget::playSound()
    2. {
    3. qDebug() << "something";
    4. m_wave->playSound( 0, 0 );
    5. timer->start(100);
    6. }
    To copy to clipboard, switch view to plain text mode 

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

  12. #12
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    I discovered the error. Was my mistake.

    Thank you
    Franco Amato

  13. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: signal / slot problem

    Quote Originally Posted by franco.amato View Post
    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!

  14. #14
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signal / slot problem

    Quote Originally Posted by Lykurg View Post
    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
    Franco Amato

Similar Threads

  1. problem with changed() signal emitted by QGraphicsScene
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2009, 13:55
  2. error when adding signal slot to a QGLWidget based class
    By john_god in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2009, 23:31
  3. retrieving signal name in a slot
    By Baschterl in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 20:44
  4. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  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.