sqlbrowser example: use unique_ptr to hold m_ui
The old code used manual memory mangement (raw new/delete) to (de)allocate the Ui struct. This is so 80s. Use an owning smart pointer to manage the memory. Ordinarily, this would have been QScopedPointer, but seeing as that doesn't have a create() method to hide the raw new, use std::unique_ptr and std::make_unique() instead. Amends 2690822428deec4f0c08f4d118d69a7c6036369e. Pick-to: 6.9 6.8 Change-Id: Icabb9154eb38630855e14094b958af0214516f6b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
9c099ef942
commit
0da2c2c4ef
@ -18,7 +18,7 @@
|
||||
|
||||
Browser::Browser(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui::Browser)
|
||||
, m_ui{std::make_unique<Ui::Browser>()}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@ -60,9 +60,7 @@ Browser::Browser(QWidget *parent)
|
||||
}
|
||||
|
||||
Browser::~Browser()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
= default;
|
||||
|
||||
void Browser::exec()
|
||||
{
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <QWidget>
|
||||
#include <QSqlTableModel>
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QSqlError)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -50,7 +52,7 @@ signals:
|
||||
void statusMessage(const QString &message);
|
||||
|
||||
private:
|
||||
Ui::Browser *m_ui;
|
||||
const std::unique_ptr<Ui::Browser> m_ui;
|
||||
};
|
||||
|
||||
class CustomModel : public QSqlTableModel
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_ui(new Ui::QSqlConnectionDialogUi)
|
||||
, m_ui{std::make_unique<Ui::QSqlConnectionDialogUi>()}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@ -24,9 +24,7 @@ QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
|
||||
}
|
||||
|
||||
QSqlConnectionDialog::~QSqlConnectionDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
= default;
|
||||
|
||||
QString QSqlConnectionDialog::driverName() const
|
||||
{
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include <memory>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
@ -31,7 +33,7 @@ public:
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
Ui::QSqlConnectionDialogUi *m_ui;
|
||||
const std::unique_ptr<Ui::QSqlConnectionDialogUi> m_ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user