Adding SubWindow to a MDI Area will not work inside a slot function

  • I am wondering if this is a known bug, or I simply missed something.

    What I want to do is simple: Adding a sub window to an MDI area.

    @mdiArea->addSubWindow(new QWidget());@

    this line of code works fine if it inside the constructor of my window class.

    But I want to add the subwindow by clicking a button.

    if the "adding sub window" code is inside the button's slot function, it will not work anymore. Nothing will appear within the mdi area.

    I am developing under Mac OS Lion with Qt4.8

    here is my code:

    @MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    addSubWindow= ui->mainToolBar->addAction("Add SubWindow");
    //This line can add a sub window to the mdi area
    //ui->mdiArea->addSubWindow(new QWidget());


    void MainWindow::onAddSubWindow()
    //but if add a sub window from a slot function, it will not work. nothing will appear within the mdi area.
    ui->mdiArea->addSubWindow(new QWidget());

    delete ui;

    here is my qt project that repros this issue :

  • This is not a bug, I figured out why after looking at the MDI example.

    I need to call SubWindow->show() after I add it to the mdi area.

Log in to reply