Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to avoid QMdiArea.subWindowActivate.window.widget() crash?
Forum Updated to NodeBB v4.3 + New Features

How to avoid QMdiArea.subWindowActivate.window.widget() crash?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 587 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1
    connect(ui->mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(subWindowActivate(QMdiSubWindow*)));
    
    void MainWindow::subWindowActivate(QMdiSubWindow *window)
    {
        qDebug() << window;
        // minimized crash, close last subwindow crash
        MdiChild *child = (MdiChild*)(window->widget());
        label1->setText(child->path);
        label3->setText(child->scodec);
    }

    https://github.com/sonichy

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      do not call methods on null or dangling/invalid pointers.
      C style downcast is always a bad idea.

      void MainWindow::subWindowActivate(QMdiSubWindow *window)
      {
          if(window){
          MdiChild *child = qobject_cast<MdiChild*>(window->widget());
          if(child){
          label1->setText(child->path);
          label3->setText(child->scodec);
      }
      }
      }
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved