Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-6289

In the MID example, there is an logic error in the member function: void MainWindow::open()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • Some future release
    • 4.3.1
    • Examples and Demos
    • None
    • Any

    Description

      A code segment in MainWindow::open():
      MdiChild *child = createMdiChild();
      if (child->loadFile(fileName))

      { statusBar()->showMessage(tr("File loaded"), 2000); child->show(); }

      else

      { child->close(); }

      Problem:
      MainWindow::createMdiChild() adds an anonymous object "subWindow" of QMdiSubWindow to the object of QMdiArea. The variable child points to a object "child" of MdiChild, and "child" is the widget of the anonymous object "subWindow".
      When child->loadFile() return false, the child->close() is called, which will result in that child is destructured because it is set (Qt::WA_DeleteOnClose). Thus, the "child" object does not exist any more. Because the widget of the "subWindow" is the "child" object, the "child" notifies its parent to remove it.
      --Now, the widget of "subWindow " is 0(NULL). – //Danger!
      The object "subWindow" has no widget in the object of QMdiArea is a dangerous state.
      Later, users can use MDI to open any file. If an user open a file, then an error occurs in the following code:

      QMdiSubWindow *existing = findMdiChild(fileName);

      MainWindow::findMdiChild() will search every widget pointed by objects of QMdiSubWindow in QMdiArea.
      The "subWindow" is accessed to return its pointed widget which is 0 now.
      A code segment in MainWindow::findMdiChild():
      MdiChild *mdiChild = qobject_cast<MdiChild *>(window->widget());
      if (mdiChild->currentFile() == canonicalFilePath) -----------------------------------//error is catched by QString::==!!!!!!!!!!!!!
      return window;

      Solution:
      The most quick solution substitues "child->close();" by "delete child->parentWidget();"
      the key point is that make all objects in QMdiArea are pointing to not 0.

      Attachments

        1. errorThrowed.PNG
          errorThrowed.PNG
          18 kB
        2. openFailed.PNG
          openFailed.PNG
          42 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            docteam Qt Documentation Team
            kangtian0 kangtian0
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes