I want to connect the addCar button signal 'clicked()' in carSelectionPage to the stacked layout slot 'setCurrentIndex(1)'. Where do I put the connect code and how do I refer to both items?
Modify as following
class CarDiary {
...
private slot:
void selectCar(void);
...
private:
};
CarDiary
::CarDiary(QWidget *parent
){
...
}
CarDiary::selectCar(void)
{
stackedLayout->setCurrentIndex(1);
}
{
...
connect(addCar, SIGNAL(clicked()), this, SLOT(selectCar())); //add this after creating addCar
return groupBox;
}
class CarDiary {
...
private slot:
void selectCar(void);
...
private:
QStackedLayout *stackedLayout;
};
CarDiary::CarDiary(QWidget *parent)
: QWidget(parent)
{
stackedLayout = new QStackedLayout;
...
}
CarDiary::selectCar(void)
{
stackedLayout->setCurrentIndex(1);
}
QGroupBox *CarDiary::carSelectionPage()
{
...
connect(addCar, SIGNAL(clicked()), this, SLOT(selectCar())); //add this after creating addCar
return groupBox;
}
To copy to clipboard, switch view to plain text mode
Alternatively if there is a better way of having separate windows which I can navigate between, that would be good.
There is no alternative, you should first understand how signals and slots work in Qt. If someone were to say an alternative, it would be to post a question in a forum, as you did.
Bookmarks