Код: Выделить всё
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent) {
setWindowTitle("Drawing Window");
setFixedSize(800, 600);
auto *layout = new QVBoxLayout(this);
auto *hlayout = new QHBoxLayout();
// Create the Button
button = new QPushButton("Load Image", this);
button->setGeometry(10, 10, 80, 30);
// Create the drawing area
drawingArea = new QLabel(this);
drawingArea->setFixedSize(512, 512);
hlayout->addStretch(1);
layout->addWidget(button);
hlayout->addWidget(drawingArea);
hlayout->addStretch(1);
layout->addLayout(hlayout);
layout->addStretch(1);
}
Код: Выделить всё
main.cpp
Код: Выделить всё
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}
Однако: CLion показывает предупреждение Утечка выделенной памяти в строках:
Код: Выделить всё
auto *layout = new QVBoxLayout(this);
auto *hlayout = new QHBoxLayout();
Код: Выделить всё
Leak_DefinetlyLost - 2 Warnings
Leak_PossiblyLost - 136 Warnings
UninitCondition - 209 Warnings
Подробнее здесь: https://stackoverflow.com/questions/791 ... qt-layouts