PDA

View Full Version : access to another ui object from mainwindow



rapid84
22nd January 2016, 19:53
Hi,
I have a ui project that has mainwindow and another ui file. The another ui file has a combobox and i want to access it from mainwindow and i want to use its selected item in mainwindow. How can i do ?

anda_skoa
23rd January 2016, 10:12
The class that uses the second UI just needs to provide a method that allows the main window to set a value on the combobox and a signal that forwards changes from he combobox to the outside of the second class.



void SecondClass::setComboIndex(int index)
{
ui->comboBox->setCurrentIndex(index);
}




SecondClass::SecondClass(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SecondClass)
{
ui->setupUi(this);
connect(ui->comboBox, &QComboBox::currentIndexChanged, this, &SecondClass::comboIndexChanged);
}


Cheers,
_

rapid84
23rd January 2016, 12:57
Thanks for reply.