diff options
author | Prasanth Ullattil <prasanth.ullattil@nokia.com> | 2010-01-19 11:49:12 (GMT) |
---|---|---|
committer | Prasanth Ullattil <prasanth.ullattil@nokia.com> | 2010-01-19 13:34:32 (GMT) |
commit | 00b3098906dd7d4cfe7be3448e4eb90506d27012 (patch) | |
tree | de45f72db40016b0cd9138810b803ed707492070 /src | |
parent | b997254ba37e3ccfaa26be7021e2b172bfd82691 (diff) | |
download | Qt-00b3098906dd7d4cfe7be3448e4eb90506d27012.zip Qt-00b3098906dd7d4cfe7be3448e4eb90506d27012.tar.gz Qt-00b3098906dd7d4cfe7be3448e4eb90506d27012.tar.bz2 |
Designer crashes when previewing QMainWindow with native Toolbar on Mac
The crash happens when a QMainWindow with a native toolbar is reparented.
While re-parenting, the QToolBar triggers a new setParent() with the
MacWindowToolBarButtonHint. This messes up the internal state, hence the
crash. To avoid re-entering setParent() for the QMainWindow, this hint
is set depending on the unifiedTitleAndToolBarOnMac property.
This patch also fixes a related issue in Cocoa, we need to remove the
reused NSToolbar from the old window while recreating the QMainWindow.
Task-number: QTBUG-7162
Reviewed-by: Richard Moe Gustavsen
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qwidget_mac.mm | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 354a666..b18830f 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -110,6 +110,7 @@ #include "qevent_p.h" #include "qdnd_p.h" #include <QtGui/qgraphicsproxywidget.h> +#include "qmainwindow.h" QT_BEGIN_NAMESPACE @@ -1721,6 +1722,15 @@ bool QWidgetPrivate::qt_widget_rgn(QWidget *widget, short wcode, RgnHandle rgn, void QWidgetPrivate::determineWindowClass() { Q_Q(QWidget); +#if !defined(QT_NO_MAINWINDOW) && !defined(QT_NO_TOOLBAR) + // Make sure that QMainWindow has the MacWindowToolBarButtonHint when the + // unifiedTitleAndToolBarOnMac property is ON. This is to avoid reentry of + // setParent() triggered by the QToolBar::event(QEvent::ParentChange). + QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q); + if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) { + data.window_flags |= Qt::MacWindowToolBarButtonHint; + } +#endif #ifndef QT_MAC_USE_COCOA // ### COCOA:Interleave these better! @@ -2743,7 +2753,9 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) } if (wasWindow) { oldToolbar = [oldWindow toolbar]; + [oldToolbar retain]; oldToolbarVisible = [oldToolbar isVisible]; + [oldWindow setToolbar:nil]; } #endif } @@ -2787,6 +2799,7 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) if (oldToolbar && !(f & Qt::FramelessWindowHint)) { OSWindowRef newWindow = qt_mac_window_for(q); [newWindow setToolbar:oldToolbar]; + [oldToolbar release]; [oldToolbar setVisible:oldToolbarVisible]; } #endif |