ここの例を見ていて、メモリリークがないかどうか疑問に思っていました。サブジェクトmem leak on deleteについて話している記事を赤くしました。ただし、QWidgets は追加されたウィジェットの所有権を保持しますが、レイアウトは保持しません。
QT コードから、レイアウトを持つ親がこのレイアウトのすべてのウィジェットの所有権を取得しているようです。ただし、ドキュメントでこれに関する参照は見られませんでした。
Window::Window()
{
editor = new QTextEdit();
QPushButton *sendButton = new QPushButton(tr("&Send message"));
connect(sendButton, SIGNAL(clicked()), this, SLOT(sendMessage()));
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addStretch();
buttonLayout->addWidget(sendButton);
buttonLayout->addStretch();
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(editor);
layout->addLayout(buttonLayout);
setWindowTitle(tr("Custom Type Sending"));
}