PDA

View Full Version : want to use signal in the class itself..



salmanmanekia
5th August 2008, 09:47
class TrainNavigation:public QWidget
{
...
private:
QPushButton *recordButton;

public slots:void setDisableSlot();

signals:
void recordClicked();
..
};

void TrainNavigation::setDisable()
{
emit recordClicked();
}
void TrainNavigation::setDisableSlot()
{
if()
recordButton->setDisabled(TRUE);
}
}


#include "TrainNavigation.h"
class TrainingUI:public QWidget
{
Q_OBJECT
public:
TrainNavigation *navigate;

TrainingUI();
virtual ~TrainingUI();
};
TrainingUI::TrainingUI()
{
navigate = new TrainNavigation(this);
connect(navigate,SIGNAL(recordClicked()),navigate, SLOT(setDisableSlot()));
navigate->setDisable();
}

In the above code i was thinking that some how i should tell in the if condition in my
TrainNavigation::setDisableSlot() function that if a button is clicked then only emit the signal..
i am doing all this because i dont want to expose my button to the higher level class that is TrainingUI class..

spirit
5th August 2008, 09:52
can you give more explanation what you want to get?

salmanmanekia
5th August 2008, 09:57
Hi,,
the only thing which i want to achieve is that that when my button is clicked i want a slot to be executed..
buti dont want to use it this way


// in the TrainingUI class
connect(navigate,recordButton->clicked(),this,SLOT(setDisableSlot()));

because in this way i have to expose my recordButton as public which i dont want ...:)

spirit
5th August 2008, 10:00
try this code


TrainNavigation::TrainNavigation(QWidget *parent) : QWidget(parent)
{
connect(recordButton, SIGNAL(clicked()), SIGNAL(recordClicked()));
}

salmanmanekia
5th August 2008, 10:06
ya ..it worked..thanks...officially ur 2nd thanks..;)