Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions

[RESOLVED] Can't emit signal on dialog close



  • Hello.

    Here is my problem I have two dialogs, and when I close firs dialog, I want that second closed too.

    I'm using signals and slots, and emiting signal from first dialog witch triggers slot in other dialog, this slot looks like this:

    @void Dialog2::CloseSecondDialog(void)
    {
    close();
    }@

    The problem is that I can't emit signal onDialogClose , it just don't woking, and I don't know why ? My code:

    @Dialog1::~Dialog1()
    {
    emit CloseSecondDialog();
    delete ui;

    }@

    I made some tests and tried to emit signal from other place for example, after buton click:

    @void Dialog1::on_pushButton_clicked()
    {
    emit CloseSecondDialog();
    }@

    And it worked perfectly. So why it's not working when Dialog is closed ?

    Sory for my english.



  • You should emit signal in "closeEvent":http://qt-project.org/doc/qt-5/qdialog.html#closeEvent not in destructor.



  • Thanks for help.

    Since one of the dialogs are model and other modeless, I got it working like this:

    @Dialog2->show();
    Dialog1->exec();
    Dialog2->close();@

    And it's working perfect for my :D.
    But I think I will do it the right way and use closeEvent.

    Thanks again for both answers.


Log in to reply