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