diff --git a/include/wx/qt/app.h b/include/wx/qt/app.h index 8ce685eb62..68d8e701d1 100644 --- a/include/wx/qt/app.h +++ b/include/wx/qt/app.h @@ -9,6 +9,8 @@ #ifndef _WX_QT_APP_H_ #define _WX_QT_APP_H_ +#include + 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 m_qtApplication; int m_qtArgc; - char **m_qtArgv; + QScopedArrayPointer m_qtArgv; wxDECLARE_DYNAMIC_CLASS_NO_COPY( wxApp ); }; diff --git a/src/qt/app.cpp b/src/qt/app.cpp index 9fcd4e7681..47aa92d2f2 100644 --- a/src/qt/app.cpp +++ b/src/qt/app.cpp @@ -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