Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open new dialog from a dialog in qt

I am trying to open a new dialog Window from a existing dialog on a a button click event,but I am not able to do this as i opened the dialog window from MainWindow.

I am trying with:

Dialog1 *New = new Dialog1();

New->show(); 

Is there a different way of opening dialog window form existing dialog Window???

like image 1000
Tanmay J Shetty Avatar asked Apr 13 '12 00:04

Tanmay J Shetty


1 Answers

There must be some other problem, because your code looks good to me. Here's how I'd do it:

#include <QtGui>

class Dialog : public QDialog
{
public:
    Dialog()
    {
        QDialog *subDialog = new QDialog;
        subDialog->setWindowTitle("Sub Dialog");
        QPushButton *button = new QPushButton("Push to open new dialog", this);
        connect(button, SIGNAL(clicked()), subDialog, SLOT(show()));
    }
};

class MainWindow : public QMainWindow
{
public:
    MainWindow()
    {
        Dialog *dialog = new Dialog;
        dialog->setWindowTitle("Dialog");
        dialog->show();
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    MainWindow w;
    w.setWindowTitle("Main Window");
    w.show();

    return a.exec();
}

By the way, note how I've connected QPushButton's "clicked" signal to QDialog's "show" slot. Very handy.

like image 89
Anthony Avatar answered Oct 31 '22 19:10

Anthony