Q
Q
Quarintium2018-10-26 23:00:08
Qt
Quarintium, 2018-10-26 23:00:08

How to pass value from child window to parent window?

Idea:
There is a form with a button. When the button is pressed, another form opens, with radio buttons and a button.
When you click on the button, the window closes and sends the value depending on the selected one. In the main form this value is "caught".
In C# it was done something like this:

//Нажатие на кнопку
void ButClic()
{
    f1 = new CrPass();
    // подписка на событие закрытия формы
    f1.FormClosing += new FormClosingEventHandler(F1_FormClosing);
    f1.ShowDialog();
}

void F1_FormClosing(object sender, FormClosingEventArgs e)
{
    string str = (sender as Form2).ReturnZn();
    if (str != "NONE")
    {
         // некий код
    }
}

How to do it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel K, 2018-10-27
@PavelK

The simplest way is through signal-slots.

D
drizt, 2018-11-14
@drizt

The value QRadioButtoncan be returned with . In the main form, you can get it with . The code will be like this:QDialog::done(int)QDialog::exec(int)

void ChildDialog::onOkButton()
{
    int result;
    // считываем значение QRadioButton
    done(result);
}

void MainDialog::showChild()
{
    ChildDialog dlg(this);
    int radioBtn = dlg.exec();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question