From 6b82ad9b2c7ed5af633e972ea2b56e3a30886d20 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sun, 5 Aug 2012 14:12:47 +0200 Subject: Ensure Rekonq (tools) menu does not crash by using a Q(Weak)Pointer --- src/webwindow/rekonqmenu.cpp | 12 ++++++++---- src/webwindow/rekonqmenu.h | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/webwindow/rekonqmenu.cpp b/src/webwindow/rekonqmenu.cpp index a5cea784..c32d71f5 100644 --- a/src/webwindow/rekonqmenu.cpp +++ b/src/webwindow/rekonqmenu.cpp @@ -51,20 +51,24 @@ void RekonqMenu::showEvent(QShowEvent* event) { KMenu::showEvent(event); - if (!m_button) + if (m_button.isNull()) return; + kDebug() << "but: " << m_button.data(); + kDebug() << "but w: " << m_button.data()->width(); + kDebug() << "but h: " << m_button.data()->height(); + // Adjust the position of the menu to be shown within the // rekonq window to reduce the cases that sub-menus might overlap // the right screen border. QPoint pos; if (layoutDirection() == Qt::RightToLeft) { - pos = m_button->mapToGlobal(QPoint(0, m_button->height())); + pos = m_button.data()->mapToGlobal(QPoint(0, m_button.data()->height())); } else { - pos = m_button->mapToGlobal(QPoint(m_button->width(), m_button->height())); + pos = m_button.data()->mapToGlobal(QPoint(m_button.data()->width(), m_button.data()->height())); pos.rx() -= width(); } @@ -91,7 +95,7 @@ void RekonqMenu::showEvent(QShowEvent* event) { if (pos.y() + height() > screen.y() + screen.height()) { - pos.ry() = m_button->mapToGlobal(QPoint(0, 0)).y() + height(); + pos.ry() = m_button.data()->mapToGlobal(QPoint(0, 0)).y() + height(); } } diff --git a/src/webwindow/rekonqmenu.h b/src/webwindow/rekonqmenu.h index 8bda008b..24aaba91 100644 --- a/src/webwindow/rekonqmenu.h +++ b/src/webwindow/rekonqmenu.h @@ -36,6 +36,9 @@ // KDE Includes #include +// Qt Includes +#include + // Forward Declarations class QWidget; @@ -58,7 +61,7 @@ protected: virtual void showEvent(QShowEvent* event); private: - QWidget *m_button; + QWeakPointer m_button; }; #endif // REKONQ_MENU_H -- cgit v1.2.1