정적으로 할당 된 경우 Qt가 모든 QObject의 자식을 이중으로 삭제하지 않고 삭제할 수있는 방법을 이해할 수 없습니다. ,Qt가 스택에 할당 된 객체를 처리하는 방법
QWidget Window(nullptr);
QPushButton button(&Window);
Window.show();
return App.exec();
//When app ends, button then Window get deleted
//because they were statically allocated
//And then, Window (should) delete button AGAIN because it's its child, thus crashing
//the program. But it doesn't. Why ?
합니까 Qt는 내가 QPushButton을 만든 방법을 알고 :
QWidget Window(nullptr);
QPushButton* button = new QPushButton(&Window);
Window.show();
return App.exec();
//When app ends, Window gets deleted
//because it was statically allocated
//And then, Window deletes button because it's its child.
그러나 나는 또한 충돌없이이 작업을 수행 할 수 있습니다 내가 그것을 일반적인 방법을 할 경우
기본적으로, 그것은 다음과 같습니다 또는 나는 무엇인가 놓쳤 느냐?
예, 당신은, 즉 무언가를 그리워 정의되지 않은 동작은 정의입니다. –
@ n.m .: 여기까지 정의되지 않은 것은 말할 수 없습니다. –
@MattiVirkkunen 아마도이 예제에서는 정의되지 않은 것이 아무것도 없습니다. 충돌이 없다는 것은 아무 것도 증명하지 못한다는 것입니다. –