Fix SIGSEGV due bad pointer in wxMessageDialog (wxQT)

m_qtWindow should be used instead of m_qtMessageBox (removed). If not, PostCreation() cannot call wxMessageDialog::GetHandle() as it is virtual (and it is called from the ctor), so it fails to set the base window pointer, raising a SIGSEGV in wxWindow::DoSetSize (for more info, see architecture in docs)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78312 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mariano Reingart
2014-12-24 19:19:27 +00:00
parent c2ecbadd3b
commit 9f009d128f
2 changed files with 21 additions and 23 deletions

View File

@@ -26,8 +26,6 @@ public:
virtual QMessageBox *GetHandle() const; virtual QMessageBox *GetHandle() const;
private:
QMessageBox *m_qtMessageBox;
}; };
#endif // _WX_QT_MSGDLG_H_ #endif // _WX_QT_MSGDLG_H_

View File

@@ -27,39 +27,39 @@ wxMessageDialog::wxMessageDialog( wxWindow *parent, const wxString& message,
const wxString& caption, long style, const wxPoint& pos ) const wxString& caption, long style, const wxPoint& pos )
: wxMessageDialogBase( parent, message, caption, style ) : wxMessageDialogBase( parent, message, caption, style )
{ {
m_qtMessageBox = new wxQtMessageDialog( parent, this ); m_qtWindow = new wxQtMessageDialog( parent, this );
// Set properties // Set properties
Move( pos ); Move( pos );
m_qtMessageBox->setText( wxQtConvertString( message ) ); GetHandle()->setText( wxQtConvertString( message ) );
m_qtMessageBox->setWindowTitle( wxQtConvertString( caption ) ); GetHandle()->setWindowTitle( wxQtConvertString( caption ) );
// Apply the style // Apply the style
SetWindowStyleFlag( style ); SetWindowStyleFlag( style );
// Buttons // Buttons
if ( style & wxOK ) if ( style & wxOK )
m_qtMessageBox->addButton( QMessageBox::Ok ); GetHandle()->addButton( QMessageBox::Ok );
if ( style & wxCANCEL ) if ( style & wxCANCEL )
m_qtMessageBox->addButton( QMessageBox::Cancel ); GetHandle()->addButton( QMessageBox::Cancel );
if ( style & wxYES_NO ) if ( style & wxYES_NO )
{ {
m_qtMessageBox->addButton( QMessageBox::Yes ); GetHandle()->addButton( QMessageBox::Yes );
m_qtMessageBox->addButton( QMessageBox::No ); GetHandle()->addButton( QMessageBox::No );
} }
// Default button // Default button
if ( style & wxNO_DEFAULT ) if ( style & wxNO_DEFAULT )
m_qtMessageBox->setDefaultButton( QMessageBox::No ); GetHandle()->setDefaultButton( QMessageBox::No );
else if ( style & wxCANCEL_DEFAULT ) else if ( style & wxCANCEL_DEFAULT )
m_qtMessageBox->setDefaultButton( QMessageBox::Cancel ); GetHandle()->setDefaultButton( QMessageBox::Cancel );
else else
{ {
// Default to OK or Yes // Default to OK or Yes
if ( style & wxOK ) if ( style & wxOK )
m_qtMessageBox->setDefaultButton( QMessageBox::Ok ); GetHandle()->setDefaultButton( QMessageBox::Ok );
else else
m_qtMessageBox->setDefaultButton( QMessageBox::Yes ); GetHandle()->setDefaultButton( QMessageBox::Yes );
} }
// Icon // Icon
@@ -67,31 +67,31 @@ wxMessageDialog::wxMessageDialog( wxWindow *parent, const wxString& message,
if ( style & wxICON_NONE ) if ( style & wxICON_NONE )
{ {
numIcons++; numIcons++;
m_qtMessageBox->setIcon( QMessageBox::NoIcon ); GetHandle()->setIcon( QMessageBox::NoIcon );
} }
if ( style & wxICON_EXCLAMATION ) if ( style & wxICON_EXCLAMATION )
{ {
numIcons++; numIcons++;
m_qtMessageBox->setIcon( QMessageBox::Warning ); GetHandle()->setIcon( QMessageBox::Warning );
} }
if ( style & wxICON_ERROR || style & wxICON_HAND ) if ( style & wxICON_ERROR || style & wxICON_HAND )
{ {
numIcons++; numIcons++;
m_qtMessageBox->setIcon( QMessageBox::Critical ); GetHandle()->setIcon( QMessageBox::Critical );
} }
if ( style & wxICON_QUESTION ) if ( style & wxICON_QUESTION )
{ {
numIcons++; numIcons++;
m_qtMessageBox->setIcon( QMessageBox::Question ); GetHandle()->setIcon( QMessageBox::Question );
} }
if ( style & wxICON_INFORMATION ) if ( style & wxICON_INFORMATION )
{ {
numIcons++; numIcons++;
m_qtMessageBox->setIcon( QMessageBox::Information ); GetHandle()->setIcon( QMessageBox::Information );
} }
wxCHECK_RET( numIcons <= 1, "Multiple icon definitions" ); wxCHECK_RET( numIcons <= 1, "Multiple icon definitions" );
@@ -99,20 +99,20 @@ wxMessageDialog::wxMessageDialog( wxWindow *parent, const wxString& message,
{ {
// Use default // Use default
if ( style & wxYES_NO ) if ( style & wxYES_NO )
m_qtMessageBox->setIcon( QMessageBox::Question ); GetHandle()->setIcon( QMessageBox::Question );
else else
m_qtMessageBox->setIcon( QMessageBox::Information ); GetHandle()->setIcon( QMessageBox::Information );
} }
if ( style & wxSTAY_ON_TOP ) if ( style & wxSTAY_ON_TOP )
m_qtMessageBox->setWindowModality( Qt::ApplicationModal ); GetHandle()->setWindowModality( Qt::ApplicationModal );
PostCreation(); PostCreation();
} }
int wxMessageDialog::ShowModal() int wxMessageDialog::ShowModal()
{ {
wxCHECK_MSG( m_qtMessageBox, -1, "Invalid dialog" ); wxCHECK_MSG( GetHandle(), -1, "Invalid dialog" );
// Exec may return a wx identifier if a close event is generated // Exec may return a wx identifier if a close event is generated
int ret = GetHandle()->exec(); int ret = GetHandle()->exec();
@@ -134,7 +134,7 @@ int wxMessageDialog::ShowModal()
QMessageBox *wxMessageDialog::GetHandle() const QMessageBox *wxMessageDialog::GetHandle() const
{ {
return m_qtMessageBox; return static_cast<QMessageBox*>(m_qtWindow);
} }
wxMessageDialog::~wxMessageDialog() wxMessageDialog::~wxMessageDialog()