Почему не происходит сбоя при назначении виджета-члена в качестве центрального виджета в QMainWindow ⇐ C++
Почему не происходит сбоя при назначении виджета-члена в качестве центрального виджета в QMainWindow
I wrote the following code which doesn't provoke any error:
main.cpp
#include "main_window.hpp" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } main_window.hpp
#pragma once #include "ui_main_window.h" #include #include class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); setCentralWidget(&view); } private: Ui::MainWindowClass ui; QGraphicsView view; }; However, Qt documentation for QMainWindow::setCentralWidget says that
Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.
Shouldn't there be a crash on finishing app because of double deleting of view: by Qt's ownership model and and by ~MainWindow()?
Источник: https://stackoverflow.com/questions/780 ... n-qmainwin
I wrote the following code which doesn't provoke any error:
main.cpp
#include "main_window.hpp" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } main_window.hpp
#pragma once #include "ui_main_window.h" #include #include class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); setCentralWidget(&view); } private: Ui::MainWindowClass ui; QGraphicsView view; }; However, Qt documentation for QMainWindow::setCentralWidget says that
Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.
Shouldn't there be a crash on finishing app because of double deleting of view: by Qt's ownership model and and by ~MainWindow()?
Источник: https://stackoverflow.com/questions/780 ... n-qmainwin
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Запретить QMainWindow увеличивать QDockWidget при переключении центрального виджета
Anonymous » » в форуме C++ - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Mypy говорит «несовместимые типы в назначении» при назначении из множественного наследства
Anonymous » » в форуме Python - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-