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. MainWindow deleteLater() segmentation fault
Forum Updated to NodeBB v4.3 + New Features

MainWindow deleteLater() segmentation fault

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 1.4k 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.
  • A Offline
    A Offline
    abarmotov
    wrote on last edited by
    #1

    If this is RTFM, point me )
    Create simple GUI App in Creator, append button and write in slot: deleteLater()
    Run it, press this button - segmentation fault take place
    In application output "double free or curruption" error shown
    Ubuntu 16.04 64Bit, Qt 5.12.0 from offline installer

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please show use you code.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 2 Replies Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Please show use you code.

        A Offline
        A Offline
        abarmotov
        wrote on last edited by abarmotov
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Please show use you code.

          A Offline
          A Offline
          abarmotov
          wrote on last edited by
          #4
          void MainWindow::on_pushButton_clicked()
          {
              deleteLater();
          }
          
          
          jsulmJ 1 Reply Last reply
          0
          • A abarmotov
            void MainWindow::on_pushButton_clicked()
            {
                deleteLater();
            }
            
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @abarmotov Why do you do this?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply
            0
            • jsulmJ jsulm

              @abarmotov Why do you do this?

              A Offline
              A Offline
              abarmotov
              wrote on last edited by
              #6

              @jsulm Why i cant ?
              Is it unsafe to call QObject::deleteLater() here ?

              jsulmJ 1 Reply Last reply
              0
              • A abarmotov

                @jsulm Why i cant ?
                Is it unsafe to call QObject::deleteLater() here ?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @abarmotov It is unusual that an object destroys itself. Can you explain why you're doing this?
                The problem is (I guess your code looks like this):

                void main()
                {
                    ...
                    MainWindow window;
                    ...
                    app.exec();
                    // Here window will be destroyed, but you call deleteLater() in in the slot -> double delete
                }
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @abarmotov It is unusual that an object destroys itself. Can you explain why you're doing this?
                  The problem is (I guess your code looks like this):

                  void main()
                  {
                      ...
                      MainWindow window;
                      ...
                      app.exec();
                      // Here window will be destroyed, but you call deleteLater() in in the slot -> double delete
                  }
                  
                  A Offline
                  A Offline
                  abarmotov
                  wrote on last edited by
                  #8

                  @jsulm yes, forgot about main.cpp )

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    So how does your main.cpp looks like? The same as jsulm posted? Then you must not call deleteLater() since you created MainWindow on the stack.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      abarmotov
                      wrote on last edited by
                      #10

                      Yes, this is default project main.cpp, i failed to saw where double free occured. But now ok.

                      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