静的に割り当てられていた場合、Qtのすべての子を削除することができません。Qtがスタックに割り当てられたオブジェクトを処理する方法
私はそれを通常の方法を行う場合、基本的に、それは次のようになります。
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.
しかし、私はまた、クラッシュせずにこれを行うことができます。
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を作成する方法を知っていますまたは私は何かが恋しいですか?
はい、あなたは未定義の動作は未定義であること、すなわち、何かを逃してください。 –
@ n.m .:私が知る限り、ここには何も定義されていないものはありません。 –
@MattiVirkkunenこの例では何も定義されていないかもしれませんが、私はクラッシュがないと何も証明しないと言っています。 –