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) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    addSubWindow= ui->mainToolBar->addAction("Add SubWindow");
    
    connect(addSubWindow,SIGNAL(triggered()),this,SLOT(onAddSubWindow()));
    
    //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());
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    here is my qt project that repros this issue :http://dl.dropbox.com/u/3315090/mdibug.zip



  • 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
 

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