⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Mdichild related problem

  • Hi,

    I got a mdichild class (derived from QPlainTextEdit).
    When I try to "play" with it (using setTabStopWidth ortrying to move its cursor for example).
    It crashed in QScopedPointer.h in the function

    @ inline T *data() const
    return d; <============ crash here with an invalid "this" value .
    the crash only appends if my mdichild already exists (i.e. if found in mdiArea->subWindowList() );
    When the mdichild does not exist yet and just created and add with mdiArea->addSubWindow(child); evrything is

    Is it a thread related problem ?
    Do i need to do something special (like waiting for the mdichild to show up) before trying to work with it ?

    Any help will be appreciated.
    Thanks in advance

  • Please give us a bit more information.

    • Are you working with worker threads?
    • What do they do?

  • No, I don't use worker threads at all.
    I started with this sample :

    And I'm trying to set the tab width here :

    @ void MainWindow::open()
    QString fileName = QFileDialog::getOpenFileName(this);
    if (!fileName.isEmpty()) {
    QMdiSubWindow *existing = findMdiChild(fileName);
    if (existing) {
    existing->MyFunctionToSetTabWidth(); <---Here

         MdiChild *child = createMdiChild();
         if (child->loadFile&#40;fileName&#41;) {
             statusBar()->showMessage(tr("File loaded"), 2000);
         } else {


  • Hm,
    in general, this function looks good. Maybe it's in the sourroundings somewhere. Did you debug the whole thing and check, whether existing points to a valid object?

  • Thanks a lot, you were right, it was in the surroundings.
    It was a bad cast. findMdiChild returns a QMdiSubWindow and not directly a widget. The solution was to cast the widget and not directly the subwindow like this :

    @ QMdiSubWindow *subw = findMdiChild(fileName);
    if (subw != NULL)
    existing = qobject_cast<MdiChild *> (subw->widget());

Log in to reply