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. "takes ownership of widget" - What is really happenning?
QtWS25 Last Chance

"takes ownership of widget" - What is really happenning?

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 931 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.
  • H Offline
    H Offline
    hbatalha
    wrote on 6 Feb 2022, 18:27 last edited by hbatalha 2 Jun 2022, 18:28
    #1

    Take the code below as an example:

    MainWindow::MainWindow()
        : QMainWindow(0)
        , ui(new Ui::MainWindow)
    {
    
        settings_button = new QToolButton(this);
    
        ui->toolBar->addWidget(settings_button);
    
    }
    

    According to the doc the toolbar takes ownership of widget. what I want to know is if because when creating the widget I gave it a parent it will be deleted twice, by mainwindow and the toolbar. When the toolbar took ownership of the widget did the mainwindow gave the widget up as its child?

    My app keeps randomly freezing when closing it and I am trying to locate the issue.

    PS: my debugger is not working properly(not getting the stack trace)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 6 Feb 2022, 18:47 last edited by
      #2

      The parent of QToolButton is first the MainWindow instance, after your call it's the QToolBar. An QObject can not have more than one parent so a double delete is not possible due to QObject's automatic destruction of the children.

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

      H 1 Reply Last reply 6 Feb 2022, 20:44
      4
      • C Christian Ehrlicher
        6 Feb 2022, 18:47

        The parent of QToolButton is first the MainWindow instance, after your call it's the QToolBar. An QObject can not have more than one parent so a double delete is not possible due to QObject's automatic destruction of the children.

        H Offline
        H Offline
        hbatalha
        wrote on 6 Feb 2022, 20:44 last edited by
        #3

        @Christian-Ehrlicher So does it mean that the code above won't cause a crash?

        C 1 Reply Last reply 7 Feb 2022, 05:05
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 6 Feb 2022, 21:07 last edited by
          #4

          Why should it? Is my explanation and the Qt documentation about QObject parent - child relationship that bad?

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

          H 1 Reply Last reply 7 Feb 2022, 09:50
          1
          • H hbatalha
            6 Feb 2022, 20:44

            @Christian-Ehrlicher So does it mean that the code above won't cause a crash?

            C Offline
            C Offline
            ChrisW67
            wrote on 7 Feb 2022, 05:05 last edited by ChrisW67 2 Jul 2022, 05:06
            #5

            @hbatalha Yes, the code will not cause a crash.

            A QObject has a singular parent object and potentially many children.

            When you call myQObject->setParent() it will check for an existing parent, find myQObject in the parent's children list and remove it, then set myQObject's parent pointer and add myQObject to the new parent's child list (There are other checks and things happening). myQObject only appears in at most one QObject's child list at a time. It will be deleted when that parent QObject is deleted.

            1 Reply Last reply
            3
            • C Christian Ehrlicher
              6 Feb 2022, 21:07

              Why should it? Is my explanation and the Qt documentation about QObject parent - child relationship that bad?

              H Offline
              H Offline
              hbatalha
              wrote on 7 Feb 2022, 09:50 last edited by
              #6

              @Christian-Ehrlicher no, not at all. that was just my disappointment since I haven't yet found the cause for my app to freeze when closing it.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 7 Feb 2022, 09:58 last edited by
                #7

                Did you already tried to see something with the debugger?

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

                H 1 Reply Last reply 8 Feb 2022, 20:21
                1
                • C Christian Ehrlicher
                  7 Feb 2022, 09:58

                  Did you already tried to see something with the debugger?

                  H Offline
                  H Offline
                  hbatalha
                  wrote on 8 Feb 2022, 20:21 last edited by
                  #8

                  @Christian-Ehrlicher yeah but my app freezes randomly so it is very difficult.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 8 Feb 2022, 20:28 last edited by
                    #9

                    When it freezes attach the debugger and see what's going on.

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

                    H 1 Reply Last reply 8 Feb 2022, 21:09
                    1
                    • C Christian Ehrlicher
                      8 Feb 2022, 20:28

                      When it freezes attach the debugger and see what's going on.

                      H Offline
                      H Offline
                      hbatalha
                      wrote on 8 Feb 2022, 21:09 last edited by
                      #10

                      @Christian-Ehrlicher the problem is I will not know when it will freeze.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 8 Feb 2022, 21:20 last edited by
                        #11

                        But when you see it - what's the problem attaching a debugger then?

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

                        H 2 Replies Last reply 9 Feb 2022, 11:03
                        0
                        • C Christian Ehrlicher
                          8 Feb 2022, 21:20

                          But when you see it - what's the problem attaching a debugger then?

                          H Offline
                          H Offline
                          hbatalha
                          wrote on 9 Feb 2022, 11:03 last edited by
                          #12

                          @Christian-Ehrlicher as stated in the OP:

                          PS: my debugger is not working properly(not getting the stack trace)

                          But I got it working yesterday and since then my app haven't frozen when closing it after numerous tries yet. I will keep trying and when/if it does crash I will get back to you here.

                          1 Reply Last reply
                          0
                          • C Christian Ehrlicher
                            8 Feb 2022, 21:20

                            But when you see it - what's the problem attaching a debugger then?

                            H Offline
                            H Offline
                            hbatalha
                            wrote on 10 Feb 2022, 16:38 last edited by
                            #13

                            @Christian-Ehrlicher It just crashed when attached to debugger and I got this in the app output:

                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(1) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(2) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(3) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(4) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(5) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(6) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(7) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(8) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(9) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(10) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(11) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(12) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(13) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(14) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(15) tid(35258) 800706BA The RPC server is unavailable.
                            onecore\com\combase\dcomrem\call.cxx(4907)\combase.dll!00007FFD40813B4B: (caller: 00007FFD40814961) ReturnHr(16) tid(35258) 800706BA The RPC server is unavailable.
                            

                            I am g searching it, have no idea what they mean.

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              ChrisW67
                              wrote on 12 Feb 2022, 06:38 last edited by
                              #14

                              Is that "onecore" reference anything to do with Xero?

                              H 1 Reply Last reply 12 Feb 2022, 07:09
                              0
                              • C ChrisW67
                                12 Feb 2022, 06:38

                                Is that "onecore" reference anything to do with Xero?

                                H Offline
                                H Offline
                                hbatalha
                                wrote on 12 Feb 2022, 07:09 last edited by
                                #15

                                @ChrisW67 I don't know. What is xero(in this context)?

                                1 Reply Last reply
                                0

                                1/15

                                6 Feb 2022, 18:27

                                • Login

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