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