Results 1 to 4 of 4

Thread: Something happened to the signals:

  1. #1
    Join Date
    Nov 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Something happened to the signals:

    I have two widgets, one of then bears the button-press handler methods and emits some signals, the second is supposed to receive them.
    The handlers are called, the connect(...) function that connects the signals from the first widget with the slots of the second returns (1), but the slots are not called. How can i fix it?
    Here's the code:

    first widget:
    Qt Code:
    1. #ifndef PLAYLISTCONTROLBUTTONWIDGET_H
    2. #define PLAYLISTCONTROLBUTTONWIDGET_H
    3.  
    4. #include <QWidget>
    5. #include "ui_playlistcontrolbuttonwidget.h"
    6.  
    7. using namespace Ui;
    8.  
    9. #include <iostream>
    10. using namespace std;
    11.  
    12. class PlaylistControlButtonWidget : public QWidget, public PlaylistControlButtonWidgetClass
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. PlaylistControlButtonWidget(QWidget *parent = 0);
    18. ~PlaylistControlButtonWidget();
    19.  
    20. private slots:
    21. void on_seekSlider_valueChanged(int);
    22. void on_prevButton_clicked();
    23. void on_playRandomButton_clicked();
    24. void on_nextButton_clicked();
    25. void on_playButton_clicked();
    26. void on_stopButton_clicked();
    27. void on_pauseButton_clicked();
    28.  
    29. signals:
    30. void Pause(void);
    31. void Stop(void);
    32. void Play(void);
    33. void Prev(void);
    34. void Rand(void);
    35. void Next(void);
    36. void SeekSliderChanged(int pos, int total);
    37.  
    38.  
    39. };
    40. #endif // PLAYLISTCONTROLBUTTONWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "playlistcontrolbuttonwidget.h"
    2.  
    3. PlaylistControlButtonWidget::PlaylistControlButtonWidget(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. setupUi(this);
    7. }
    8.  
    9. PlaylistControlButtonWidget::~PlaylistControlButtonWidget()
    10. {
    11. }
    12.  
    13. void PlaylistControlButtonWidget::on_pauseButton_clicked()
    14. {
    15. emit Pause();
    16. }
    17.  
    18. void PlaylistControlButtonWidget::on_stopButton_clicked()
    19. {
    20. emit Stop();
    21. }
    22.  
    23. void PlaylistControlButtonWidget::on_playButton_clicked()
    24. {
    25. cout << "PLY"<<endl;
    26. emit Play();
    27. }
    28.  
    29. void PlaylistControlButtonWidget::on_nextButton_clicked()
    30. {
    31. emit Next();
    32. }
    33.  
    34. void PlaylistControlButtonWidget::on_playRandomButton_clicked()
    35. {
    36. emit Rand();
    37. }
    38.  
    39. void PlaylistControlButtonWidget::on_prevButton_clicked()
    40. {
    41. emit Prev();
    42. }
    43.  
    44. void PlaylistControlButtonWidget::on_seekSlider_valueChanged(int pos)
    45. {
    46. emit SeekSliderChanged(pos, 1000);
    47. }
    To copy to clipboard, switch view to plain text mode 


    and the second:

    Qt Code:
    1. #ifndef PLAYLISTVIEWWIDGET_H
    2. #define PLAYLISTVIEWWIDGET_H
    3. #include <QtGui/QtGui>
    4. #include <QtCore/QtCore>
    5. #include <QWidget>
    6. #include "ui_playlistviewwidget.h"
    7.  
    8. #include "playlistcontrolbuttonwidget.h"
    9.  
    10. using namespace Ui;
    11.  
    12. #include <iostream>
    13. using namespace std;
    14.  
    15.  
    16. class PlaylistViewWidget : public QWidget, public PlaylistViewWidgetClass
    17. {
    18. Q_OBJECT
    19. public:
    20. PlaylistViewWidget(QWidget *parent = 0);
    21. ~PlaylistViewWidget();
    22.  
    23. QTableView* tableView;
    24. QWidget* playlistControlsWidget;
    25. QToolBar* playbackToolBar;
    26. QMenu* playbackMenu;
    27.  
    28. public slots:
    29. void OnCurrentChanged(int newTabIndex);
    30. void OnPlay();//обработчики
    31. void OnNext();
    32. void OnPrev();
    33. void OnRand();
    34. void OnPause();
    35. void OnSeek(int pos, int total);
    36.  
    37.  
    38. signals:
    39. void AddTracksRequest(QStringList trackPaths);
    40. void CurrentPlaylistChanged(int newTabId);
    41. void CurrentTrackChanged(int newTrackId);
    42. void PlayCurrent();
    43. void PauseUnpause();
    44.  
    45. };
    46.  
    47. #endif // PLAYLISTVIEWWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "playlistviewwidget.h"
    2.  
    3. PlaylistViewWidget::PlaylistViewWidget(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. setupUi(this);
    7. playlistControlsWidget = new PlaylistControlButtonWidget;
    8. cout << "@@@"<<endl;
    9. // void OnPlay();//обработчики
    10. // void OnNext();
    11. // void OnPrev();
    12. // void OnRand();
    13. // void OnPause();
    14. // void OnSeek(int pos);
    15. playbackToolBar = new QToolBar("Playback Toolbar");
    16. playbackToolBar->addWidget(playlistControlsWidget);
    17.  
    18. cout <<connect(playlistControlsWidget, SIGNAL(Play()), this, SLOT(OnPlay()) )<<endl;
    19. cout << connect(playlistControlsWidget, SIGNAL(Next()), this, SLOT(OnNext()) )<<endl;
    20. cout << connect(playlistControlsWidget, SIGNAL(Prev()), this, SLOT(OnPrev()) )<<endl;
    21. cout << connect(playlistControlsWidget, SIGNAL(Rand()), this, SLOT(OnRand()) )<<endl;
    22. cout << connect(playlistControlsWidget, SIGNAL(Pause()), this, SLOT(OnPause()) )<<endl;
    23. cout << connect(playlistControlsWidget, SIGNAL(SeekSliderChanged(int, int)), this, SLOT(OnSeek(int, int)) )<<endl;
    24.  
    25. cout << connect(playlistTabWidget, SIGNAL(currentChanged(int)), this, SLOT(OnCurrentChanged(int)))<<endl;
    26.  
    27. }
    28.  
    29. PlaylistViewWidget::~PlaylistViewWidget()
    30. {
    31.  
    32. }
    33.  
    34. void PlaylistViewWidget::OnCurrentChanged( int newTabIndex)
    35. {
    36. exit(-1);
    37. cout << "CurChan "<<newTabIndex<<endl;
    38. }
    39.  
    40. void PlaylistViewWidget::OnPlay()
    41. {
    42. exit(-1);
    43. cout << "play "<<endl;
    44. }
    45.  
    46. void PlaylistViewWidget::OnNext()
    47. {
    48. cout << "nxt "<<endl;
    49. }
    50.  
    51. void PlaylistViewWidget::OnPrev()
    52. {
    53. cout << "prev "<<endl;
    54. }
    55.  
    56. void PlaylistViewWidget::OnRand()
    57. {
    58. cout << "rand "<<endl;
    59. }
    60.  
    61. void PlaylistViewWidget::OnPause()
    62. {
    63. cout << "pause "<<endl;
    64. }
    65.  
    66. void PlaylistViewWidget::OnSeek( int pos, int total )
    67. {
    68. cout << "seek "<<pos<<endl;
    69. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by YaK; 23rd May 2009 at 15:41. Reason: spelling error

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Something happened to the signals:

    are you sure your PlaylistControlButtonWidget that you insert into a (new) QToolBar is actually added to your window (in other words: why dont you add the new toolbar to the window)?

  3. #3
    Join Date
    Nov 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Something happened to the signals:

    Quote Originally Posted by caduel View Post
    are you sure your PlaylistControlButtonWidget that you insert into a (new) QToolBar is actually added to your window (in other words: why dont you add the new toolbar to the window)?
    Yes. I saw the toolbar with that widget on my main window.

    Qt Code:
    1. void PlaylistController::AttachTo( QMainWindow* mainwnd )
    2. {
    3. mainwnd->addToolBar(controlsToolBar);//the 1st widget
    4. mainwnd->setCentralWidget(playlistViewWidget);//the 2ndwidget
    5. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Nov 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Something happened to the signals:

    I've tracked the bug. That was the toolbar from other similar widget! =)))

Similar Threads

  1. QStateMachine and signals
    By rossm in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2009, 10:43
  2. Signals are delayed on X11?
    By Cruz in forum Qt Programming
    Replies: 13
    Last Post: 18th February 2009, 12:59
  3. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  4. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18
  5. KDE Signals
    By chombium in forum KDE Forum
    Replies: 1
    Last Post: 25th January 2006, 18:45

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.