"takes ownership of widget" - What is really happenning?
-
wrote on 6 Feb 2022, 18:27 last edited by hbatalha 2 Jun 2022, 18:28
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)
-
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.
-
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.
wrote on 6 Feb 2022, 20:44 last edited by@Christian-Ehrlicher So does it mean that the code above won't cause a crash?
-
Why should it? Is my explanation and the Qt documentation about QObject parent - child relationship that bad?
-
@Christian-Ehrlicher So does it mean that the code above won't cause a crash?
wrote on 7 Feb 2022, 05:05 last edited by ChrisW67 2 Jul 2022, 05:06@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.
-
Why should it? Is my explanation and the Qt documentation about QObject parent - child relationship that bad?
wrote on 7 Feb 2022, 09:50 last edited by@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.
-
Did you already tried to see something with the debugger?
-
Did you already tried to see something with the debugger?
wrote on 8 Feb 2022, 20:21 last edited by@Christian-Ehrlicher yeah but my app freezes randomly so it is very difficult.
-
When it freezes attach the debugger and see what's going on.
-
When it freezes attach the debugger and see what's going on.
wrote on 8 Feb 2022, 21:09 last edited by@Christian-Ehrlicher the problem is I will not know when it will freeze.
-
But when you see it - what's the problem attaching a debugger then?
-
But when you see it - what's the problem attaching a debugger then?
wrote on 9 Feb 2022, 11:03 last edited by@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.
-
But when you see it - what's the problem attaching a debugger then?
wrote on 10 Feb 2022, 16:38 last edited by@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.
-
wrote on 12 Feb 2022, 06:38 last edited by
Is that "onecore" reference anything to do with Xero?
2/15