[SOLVED]Show and use a custom dialog from within a widget or mainwindow



  • Hi all,
    I have a 'stupid' question about using a costum dialog from within a widget/mainwindow.
    I have a widget with a pushbutton, when i push the button i want to show a custom dialog and use its input to work with inside the first widget.
    When i try this from within 'main.cpp' it works without a problem, but when i use the same from within the widget nothing seems to happen.
    Does anybody know what im doing wrong or better, where i have to look for it?
    This seems to not work:
    @
    //filename is widget.cpp
    #include "dialog.h"
    void Widget::on_pushButton_clicked()
    {
    this.hide(); //works
    Dialog d; // doesnt work?
    d.show(); // doesnt work
    }
    @
    This works:
    @
    //filename is main.cpp
    #include "dialog.h"
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Dialog d; //works
    d.show(); //works
    return a.exec();
    }
    @

    I know that i can make a function within the main.cpp to get it work, but i want to use it from within the widget.cpp and not use the main.cpp for functions ed. Is this possible or is it a really stupid question?

    Thanks in advance,
    vinb.



  • You should not hide your main widget.

    You should call d.exec() on the dialog. This opens the new window as modal dialog, i.e. it blocks input to all other windows while it is open. exec() returns when the dialog is closed (either by accept() or by reject(). See the docs of "QDialog":http://doc.qt.nokia.com/4.7/qdialog.html for some more information.



  • This looks a lot like another, "very recent discussion":http://developer.qt.nokia.com/forums/viewthread/4649/ here. You did "search before asking":http://www.catb.org/~esr/faqs/smart-questions.html#before, didn't you?



  • Thanks both!
    And yes i've searched but with the wrong keywords i quess. :)
    Sorry, for wasting your time.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.