PDA

View Full Version : Something happened to the signals:



YaK
23rd May 2009, 15:41
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:


#ifndef PLAYLISTCONTROLBUTTONWIDGET_H
#define PLAYLISTCONTROLBUTTONWIDGET_H

#include <QWidget>
#include "ui_playlistcontrolbuttonwidget.h"

using namespace Ui;

#include <iostream>
using namespace std;

class PlaylistControlButtonWidget : public QWidget, public PlaylistControlButtonWidgetClass
{
Q_OBJECT

public:
PlaylistControlButtonWidget(QWidget *parent = 0);
~PlaylistControlButtonWidget();

private slots:
void on_seekSlider_valueChanged(int);
void on_prevButton_clicked();
void on_playRandomButton_clicked();
void on_nextButton_clicked();
void on_playButton_clicked();
void on_stopButton_clicked();
void on_pauseButton_clicked();

signals:
void Pause(void);
void Stop(void);
void Play(void);
void Prev(void);
void Rand(void);
void Next(void);
void SeekSliderChanged(int pos, int total);


};
#endif // PLAYLISTCONTROLBUTTONWIDGET_H





#include "playlistcontrolbuttonwidget.h"

PlaylistControlButtonWidget::PlaylistControlButton Widget(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}

PlaylistControlButtonWidget::~PlaylistControlButto nWidget()
{
}

void PlaylistControlButtonWidget::on_pauseButton_clicke d()
{
emit Pause();
}

void PlaylistControlButtonWidget::on_stopButton_clicked ()
{
emit Stop();
}

void PlaylistControlButtonWidget::on_playButton_clicked ()
{
cout << "PLY"<<endl;
emit Play();
}

void PlaylistControlButtonWidget::on_nextButton_clicked ()
{
emit Next();
}

void PlaylistControlButtonWidget::on_playRandomButton_c licked()
{
emit Rand();
}

void PlaylistControlButtonWidget::on_prevButton_clicked ()
{
emit Prev();
}

void PlaylistControlButtonWidget::on_seekSlider_valueCh anged(int pos)
{
emit SeekSliderChanged(pos, 1000);
}



and the second:


#ifndef PLAYLISTVIEWWIDGET_H
#define PLAYLISTVIEWWIDGET_H
#include <QtGui/QtGui>
#include <QtCore/QtCore>
#include <QWidget>
#include "ui_playlistviewwidget.h"

#include "playlistcontrolbuttonwidget.h"

using namespace Ui;

#include <iostream>
using namespace std;


class PlaylistViewWidget : public QWidget, public PlaylistViewWidgetClass
{
Q_OBJECT
public:
PlaylistViewWidget(QWidget *parent = 0);
~PlaylistViewWidget();

QTableView* tableView;
QWidget* playlistControlsWidget;
QToolBar* playbackToolBar;
QMenu* playbackMenu;

public slots:
void OnCurrentChanged(int newTabIndex);
void OnPlay();//обработчики
void OnNext();
void OnPrev();
void OnRand();
void OnPause();
void OnSeek(int pos, int total);


signals:
void AddTracksRequest(QStringList trackPaths);
void CurrentPlaylistChanged(int newTabId);
void CurrentTrackChanged(int newTrackId);
void PlayCurrent();
void PauseUnpause();

};

#endif // PLAYLISTVIEWWIDGET_H



#include "playlistviewwidget.h"

PlaylistViewWidget::PlaylistViewWidget(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
playlistControlsWidget = new PlaylistControlButtonWidget;
cout << "@@@"<<endl;
// void OnPlay();//обработчики
// void OnNext();
// void OnPrev();
// void OnRand();
// void OnPause();
// void OnSeek(int pos);
playbackToolBar = new QToolBar("Playback Toolbar");
playbackToolBar->addWidget(playlistControlsWidget);

cout <<connect(playlistControlsWidget, SIGNAL(Play()), this, SLOT(OnPlay()) )<<endl;
cout << connect(playlistControlsWidget, SIGNAL(Next()), this, SLOT(OnNext()) )<<endl;
cout << connect(playlistControlsWidget, SIGNAL(Prev()), this, SLOT(OnPrev()) )<<endl;
cout << connect(playlistControlsWidget, SIGNAL(Rand()), this, SLOT(OnRand()) )<<endl;
cout << connect(playlistControlsWidget, SIGNAL(Pause()), this, SLOT(OnPause()) )<<endl;
cout << connect(playlistControlsWidget, SIGNAL(SeekSliderChanged(int, int)), this, SLOT(OnSeek(int, int)) )<<endl;

cout << connect(playlistTabWidget, SIGNAL(currentChanged(int)), this, SLOT(OnCurrentChanged(int)))<<endl;

}

PlaylistViewWidget::~PlaylistViewWidget()
{

}

void PlaylistViewWidget::OnCurrentChanged( int newTabIndex)
{
exit(-1);
cout << "CurChan "<<newTabIndex<<endl;
}

void PlaylistViewWidget::OnPlay()
{
exit(-1);
cout << "play "<<endl;
}

void PlaylistViewWidget::OnNext()
{
cout << "nxt "<<endl;
}

void PlaylistViewWidget::OnPrev()
{
cout << "prev "<<endl;
}

void PlaylistViewWidget::OnRand()
{
cout << "rand "<<endl;
}

void PlaylistViewWidget::OnPause()
{
cout << "pause "<<endl;
}

void PlaylistViewWidget::OnSeek( int pos, int total )
{
cout << "seek "<<pos<<endl;
}

caduel
23rd May 2009, 15:46
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)?

YaK
23rd May 2009, 15:54
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.



void PlaylistController::AttachTo( QMainWindow* mainwnd )
{
mainwnd->addToolBar(controlsToolBar);//the 1st widget
mainwnd->setCentralWidget(playlistViewWidget);//the 2ndwidget
}

YaK
24th May 2009, 04:19
I've tracked the bug. That was the toolbar from other similar widget! =)))