diff --git a/include/wx/qt/accel.h b/include/wx/qt/accel.h index d402f4941a..ee9734f6c7 100644 --- a/include/wx/qt/accel.h +++ b/include/wx/qt/accel.h @@ -43,7 +43,7 @@ public: wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]); // Implementation - QList < QShortcut* > *ConvertShortcutTable( QWidget *parent ) const; + wxVector ConvertShortcutTable( QWidget *parent ) const; bool Ok() const { return IsOk(); } bool IsOk() const; diff --git a/include/wx/qt/window.h b/include/wx/qt/window.h index 7951ed5436..25290319c6 100644 --- a/include/wx/qt/window.h +++ b/include/wx/qt/window.h @@ -234,7 +234,7 @@ private: bool m_mouseInside; #if wxUSE_ACCEL - QScopedPointer< QList > m_qtShortcuts; // always allocated + wxVector m_qtShortcuts; // owned by whatever GetHandle() returns QScopedPointer m_qtShortcutHandler; // always allocated bool m_processingShortcut; #endif // wxUSE_ACCEL diff --git a/src/qt/accel.cpp b/src/qt/accel.cpp index 6e258f4db8..ea35fb28fc 100644 --- a/src/qt/accel.cpp +++ b/src/qt/accel.cpp @@ -82,16 +82,17 @@ wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[] } } -QList< QShortcut* > *wxAcceleratorTable::ConvertShortcutTable( QWidget *parent ) const +wxVector wxAcceleratorTable::ConvertShortcutTable( QWidget *parent ) const { - QList< QShortcut* > *qtList = new QList< QShortcut* >; + wxVector shortcuts; - for ( wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst(); node; node = node->GetNext() ) + for ( wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst(); + node; node = node->GetNext() ) { - qtList->push_back(ConvertAccelerator( node->GetData(), parent )); + shortcuts.push_back(ConvertAccelerator(node->GetData(), parent)); } - return qtList; + return shortcuts; } wxObjectRefData *wxAcceleratorTable::CreateRefData() const diff --git a/src/qt/window.cpp b/src/qt/window.cpp index 81ee557427..bfc7672e0e 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -248,16 +248,6 @@ wxWindowQt::~wxWindowQt() DestroyChildren(); // This also destroys scrollbars -#if wxUSE_ACCEL - if ( m_qtShortcuts ) - { - for ( int i = 0; i < m_qtShortcuts->size(); ++i ) - { - delete m_qtShortcuts->at(i); - } - } -#endif - #if wxUSE_DRAG_AND_DROP SetDropTarget(NULL); #endif @@ -994,22 +984,25 @@ bool wxWindowQt::DoPopupMenu(wxMenu *menu, int x, int y) #if wxUSE_ACCEL void wxWindowQt::SetAcceleratorTable( const wxAcceleratorTable& accel ) { + wxCHECK_RET(GetHandle(), "Window has not been created"); + wxWindowBase::SetAcceleratorTable( accel ); - if ( m_qtShortcuts ) + // Disable previously set accelerators + for ( wxVector::const_iterator it = m_qtShortcuts.begin(); + it != m_qtShortcuts.end(); ++it ) { - // Disable previously set accelerators - while ( !m_qtShortcuts->isEmpty() ) - delete m_qtShortcuts->takeFirst(); + delete *it; } - m_qtShortcuts.reset(accel.ConvertShortcutTable(GetHandle())); + m_qtShortcuts = accel.ConvertShortcutTable(GetHandle()); // Connect shortcuts to window - Q_FOREACH( QShortcut *s, *m_qtShortcuts ) + for ( wxVector::const_iterator it = m_qtShortcuts.begin(); + it != m_qtShortcuts.end(); ++it ) { - QObject::connect( s, &QShortcut::activated, m_qtShortcutHandler.get(), &wxQtShortcutHandler::activated ); - QObject::connect( s, &QShortcut::activatedAmbiguously, m_qtShortcutHandler.get(), &wxQtShortcutHandler::activated ); + QObject::connect( *it, &QShortcut::activated, m_qtShortcutHandler.get(), &wxQtShortcutHandler::activated ); + QObject::connect( *it, &QShortcut::activatedAmbiguously, m_qtShortcutHandler.get(), &wxQtShortcutHandler::activated ); } } #endif // wxUSE_ACCEL