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. Change-Id: Icabb9154eb38630855e14094b958af0214516f6b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 0da2c2c4ef2219967db87021eece2a60b6e207af) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 88600c30964bc1d11ed09e3dddd4cbe4477f02d3)
This commit is contained in:
parent
ef77a08f76
commit
9be434b3b1
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
Browser::Browser(QWidget *parent)
|
Browser::Browser(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_ui(new Ui::Browser)
|
, m_ui{std::make_unique<Ui::Browser>()}
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
@ -60,9 +60,7 @@ Browser::Browser(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Browser::~Browser()
|
Browser::~Browser()
|
||||||
{
|
= default;
|
||||||
delete m_ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Browser::exec()
|
void Browser::exec()
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QSqlTableModel>
|
#include <QSqlTableModel>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QSqlError)
|
QT_FORWARD_DECLARE_CLASS(QSqlError)
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -50,7 +52,7 @@ signals:
|
|||||||
void statusMessage(const QString &message);
|
void statusMessage(const QString &message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Browser *m_ui;
|
const std::unique_ptr<Ui::Browser> m_ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CustomModel : public QSqlTableModel
|
class CustomModel : public QSqlTableModel
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
|
QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::QSqlConnectionDialogUi)
|
, m_ui{std::make_unique<Ui::QSqlConnectionDialogUi>()}
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
@ -24,9 +24,7 @@ QSqlConnectionDialog::QSqlConnectionDialog(QWidget *parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSqlConnectionDialog::~QSqlConnectionDialog()
|
QSqlConnectionDialog::~QSqlConnectionDialog()
|
||||||
{
|
= default;
|
||||||
delete m_ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QSqlConnectionDialog::driverName() const
|
QString QSqlConnectionDialog::driverName() const
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -31,7 +33,7 @@ public:
|
|||||||
void accept() override;
|
void accept() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::QSqlConnectionDialogUi *m_ui;
|
const std::unique_ptr<Ui::QSqlConnectionDialogUi> m_ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user