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. Irregular access violation when switching active subwindow in an MDI application
Forum Update on Tuesday, May 27th 2025

Irregular access violation when switching active subwindow in an MDI application

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.1k Views 2 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #6

    What happens if you don't ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • O Offline
      O Offline
      olowo726
      wrote on last edited by
      #7

      Same thing, no difference

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #8

        Do you get the same issue if you create a default application and use the code from the documentation as is ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • O Offline
          O Offline
          olowo726
          wrote on last edited by
          #9

          I modified the mdi example to read

          MdiChild *MainWindow::createMdiChild()
          {
              MdiChild *child = new MdiChild;
              QMdiSubWindow *subWindow1 = new QMdiSubWindow;
              subWindow1->setWidget(child);
              subWindow1->setAttribute(Qt::WA_DeleteOnClose);
              mdiArea->addSubWindow(subWindow1);
          
          #ifndef QT_NO_CLIPBOARD
              connect(child, &QTextEdit::copyAvailable, cutAct, &QAction::setEnabled);
              connect(child, &QTextEdit::copyAvailable, copyAct, &QAction::setEnabled);
          #endif
          
              return child;
          }
          

          i.e. to be according to the documentation. That seems to work fine.

          JonBJ 1 Reply Last reply
          0
          • O olowo726

            I modified the mdi example to read

            MdiChild *MainWindow::createMdiChild()
            {
                MdiChild *child = new MdiChild;
                QMdiSubWindow *subWindow1 = new QMdiSubWindow;
                subWindow1->setWidget(child);
                subWindow1->setAttribute(Qt::WA_DeleteOnClose);
                mdiArea->addSubWindow(subWindow1);
            
            #ifndef QT_NO_CLIPBOARD
                connect(child, &QTextEdit::copyAvailable, cutAct, &QAction::setEnabled);
                connect(child, &QTextEdit::copyAvailable, copyAct, &QAction::setEnabled);
            #endif
            
                return child;
            }
            

            i.e. to be according to the documentation. That seems to work fine.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #10

            @olowo726
            The difference appears to be that you subWindow1->setAttribute(Qt::WA_DeleteOnClose); after subWindow1->setWidget(child);, in your earlier one you set it before setting the child widget, does that really alter the behaviour?

            1 Reply Last reply
            0
            • O Offline
              O Offline
              olowo726
              wrote on last edited by
              #11

              No difference (just tested)

              JonBJ 1 Reply Last reply
              0
              • O olowo726

                No difference (just tested)

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #12

                @olowo726
                :) As I thought! In which case, only me, but I'd want to know what is different about their example code compared to your original attempt? Maybe if you retry your original attempt it will work now?! Anyway, up to you, you can just stick with what you do have working now.

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  olowo726
                  wrote on last edited by
                  #13

                  Sorry, I formulated myself badly, regarless of the order of the statement the application crashes.

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    olowo726
                    wrote on last edited by
                    #14

                    I've solved this now but actually I don't know exactly why.

                    My application have several MDI areas which the user can switch between. I had forgotten to disconnect the tile etc. menu choices from the old MDI are when the user switched MDI area. When I corrected that the crash disappeared as well indicating that the old signal connections somehow loomed. However I don't know why, I think that the signals should have been automatically disconnected when the objects were destroyed.

                    mrjjM 1 Reply Last reply
                    0
                    • O olowo726

                      I've solved this now but actually I don't know exactly why.

                      My application have several MDI areas which the user can switch between. I had forgotten to disconnect the tile etc. menu choices from the old MDI are when the user switched MDI area. When I corrected that the crash disappeared as well indicating that the old signal connections somehow loomed. However I don't know why, I think that the signals should have been automatically disconnected when the objects were destroyed.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      @olowo726

                      Hi
                      Did you verify the objects were actually destroyed?
                      Else that would explain why they are still connected.

                      1 Reply Last reply
                      0

                      • Login

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