mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
qt: Avoid shutdownwindow-related memory leak
Store a reference to the shutdown window on BitcoinApplication, so that it will be deleted when exiting the main loop.
This commit is contained in:
parent
e4f126a7ba
commit
5204598f8d
@ -245,6 +245,7 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
int returnValue;
|
int returnValue;
|
||||||
const PlatformStyle *platformStyle;
|
const PlatformStyle *platformStyle;
|
||||||
|
std::unique_ptr<QWidget> shutdownWindow;
|
||||||
|
|
||||||
void startThread();
|
void startThread();
|
||||||
};
|
};
|
||||||
@ -411,7 +412,7 @@ void BitcoinApplication::requestShutdown()
|
|||||||
// Show a simple window indicating shutdown status
|
// Show a simple window indicating shutdown status
|
||||||
// Do this first as some of the steps may take some time below,
|
// Do this first as some of the steps may take some time below,
|
||||||
// for example the RPC console may still be executing a command.
|
// for example the RPC console may still be executing a command.
|
||||||
ShutdownWindow::showShutdownWindow(window);
|
shutdownWindow.reset(ShutdownWindow::showShutdownWindow(window));
|
||||||
|
|
||||||
qDebug() << __func__ << ": Requesting shutdown";
|
qDebug() << __func__ << ": Requesting shutdown";
|
||||||
startThread();
|
startThread();
|
||||||
|
@ -171,22 +171,20 @@ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f):
|
|||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
|
QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window)
|
||||||
{
|
{
|
||||||
if (!window)
|
if (!window)
|
||||||
return;
|
return nullptr;
|
||||||
|
|
||||||
// Show a simple window indicating shutdown status
|
// Show a simple window indicating shutdown status
|
||||||
QWidget *shutdownWindow = new ShutdownWindow();
|
QWidget *shutdownWindow = new ShutdownWindow();
|
||||||
// We don't hold a direct pointer to the shutdown window after creation, so use
|
|
||||||
// Qt::WA_DeleteOnClose to make sure that the window will be deleted eventually.
|
|
||||||
shutdownWindow->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
shutdownWindow->setWindowTitle(window->windowTitle());
|
shutdownWindow->setWindowTitle(window->windowTitle());
|
||||||
|
|
||||||
// Center shutdown window at where main window was
|
// Center shutdown window at where main window was
|
||||||
const QPoint global = window->mapToGlobal(window->rect().center());
|
const QPoint global = window->mapToGlobal(window->rect().center());
|
||||||
shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
|
shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2);
|
||||||
shutdownWindow->show();
|
shutdownWindow->show();
|
||||||
|
return shutdownWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownWindow::closeEvent(QCloseEvent *event)
|
void ShutdownWindow::closeEvent(QCloseEvent *event)
|
||||||
|
@ -43,7 +43,7 @@ class ShutdownWindow : public QWidget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0);
|
ShutdownWindow(QWidget *parent=0, Qt::WindowFlags f=0);
|
||||||
static void showShutdownWindow(BitcoinGUI *window);
|
static QWidget *showShutdownWindow(BitcoinGUI *window);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
Loading…
Reference in New Issue
Block a user