Don't leak QApplication and command line arguments
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#ifndef _WX_QT_APP_H_
|
||||
#define _WX_QT_APP_H_
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
|
||||
class QApplication;
|
||||
class WXDLLIMPEXP_CORE wxApp : public wxAppBase
|
||||
{
|
||||
@@ -19,9 +21,9 @@ public:
|
||||
virtual bool Initialize(int& argc, wxChar **argv);
|
||||
|
||||
private:
|
||||
QApplication *m_qtApplication;
|
||||
QScopedPointer<QApplication> m_qtApplication;
|
||||
int m_qtArgc;
|
||||
char **m_qtArgv;
|
||||
QScopedArrayPointer<char*> m_qtArgv;
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxApp );
|
||||
};
|
||||
|
@@ -19,19 +19,16 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler);
|
||||
|
||||
wxApp::wxApp()
|
||||
{
|
||||
m_qtApplication = NULL;
|
||||
m_qtArgc = 0;
|
||||
m_qtArgv = NULL;
|
||||
}
|
||||
|
||||
|
||||
wxApp::~wxApp()
|
||||
{
|
||||
// Only delete if the app was actually initialized
|
||||
if ( m_qtApplication != NULL )
|
||||
// Delete command line arguments
|
||||
for ( int i = 0; i < m_qtArgc; ++i )
|
||||
{
|
||||
m_qtApplication->deleteLater();
|
||||
delete [] m_qtArgv;
|
||||
delete m_qtArgv[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +46,7 @@ bool wxApp::Initialize( int &argc, wxChar **argv )
|
||||
// TODO: Check whether new/strdup etc. can be replaced with std::vector<>.
|
||||
|
||||
// Clone and store arguments
|
||||
m_qtArgv = new char *[argc + 1];
|
||||
m_qtArgv.reset(new char* [argc + 1]);
|
||||
for ( int i = 0; i < argc; i++ )
|
||||
{
|
||||
m_qtArgv[i] = wxStrdupA(wxConvUTF8.cWX2MB(argv[i]));
|
||||
@@ -57,7 +54,7 @@ bool wxApp::Initialize( int &argc, wxChar **argv )
|
||||
m_qtArgv[argc] = NULL;
|
||||
m_qtArgc = argc;
|
||||
|
||||
m_qtApplication = new QApplication( m_qtArgc, m_qtArgv );
|
||||
m_qtApplication.reset(new QApplication(m_qtArgc, m_qtArgv.data()));
|
||||
|
||||
// Use the args returned by Qt as it may have deleted (processed) some of them
|
||||
// Using QApplication::arguments() forces argument processing
|
||||
|
Reference in New Issue
Block a user