summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shaw <qt-info@nokia.com>2010-01-18 10:05:46 +0100
committerAndy Shaw <qt-info@nokia.com>2010-01-18 10:05:46 +0100
commit7e76201808549c0837d1a5154ed8737fb0296c00 (patch)
treec8e598d84f2967cd3571f06fd3e4db73be8b8386
parenteccddae15a5e675e3b72a72b10457a5e9ea340b7 (diff)
downloadqt4-tools-7e76201808549c0837d1a5154ed8737fb0296c00.tar.gz
Fixes: When calling QDesktopWidget::screenGeometry() with a null
pointer then it should not crash but warn instead. Task: - RevBy: Andreas AutoTest: Included Details: This also fixes availableGeometry() as well to warn under the same circumstances.
-rw-r--r--src/gui/kernel/qdesktopwidget.cpp10
-rw-r--r--tests/auto/qdesktopwidget/tst_qdesktopwidget.cpp25
2 files changed, 35 insertions, 0 deletions
diff --git a/src/gui/kernel/qdesktopwidget.cpp b/src/gui/kernel/qdesktopwidget.cpp
index c8a437348b..24b4e5786a 100644
--- a/src/gui/kernel/qdesktopwidget.cpp
+++ b/src/gui/kernel/qdesktopwidget.cpp
@@ -47,6 +47,11 @@ QT_BEGIN_NAMESPACE
const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const
{
+ if (!widget) {
+ qWarning("QDesktopWidget::screenGeometry(): Attempt "
+ "to get the screen geometry of a null widget");
+ return QRect();
+ }
QRect rect = QWidgetPrivate::screenGeometry(widget);
if (rect.isNull())
return screenGeometry(screenNumber(widget));
@@ -55,6 +60,11 @@ const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const
const QRect QDesktopWidget::availableGeometry(const QWidget *widget) const
{
+ if (!widget) {
+ qWarning("QDesktopWidget::availableGeometry(): Attempt "
+ "to get the available geometry of a null widget");
+ return QRect();
+ }
QRect rect = QWidgetPrivate::screenGeometry(widget);
if (rect.isNull())
return availableGeometry(screenNumber(widget));
diff --git a/tests/auto/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/qdesktopwidget/tst_qdesktopwidget.cpp
index b9d9d7e164..d846615d0d 100644
--- a/tests/auto/qdesktopwidget/tst_qdesktopwidget.cpp
+++ b/tests/auto/qdesktopwidget/tst_qdesktopwidget.cpp
@@ -64,6 +64,7 @@ private slots:
void screenNumberForQWidget();
void screenNumberForQPoint();
void availableGeometry();
+ void screenGeometry();
};
tst_QDesktopWidget::tst_QDesktopWidget()
@@ -98,6 +99,9 @@ void tst_QDesktopWidget::primaryScreen()
void tst_QDesktopWidget::availableGeometry()
{
QDesktopWidget desktop;
+ QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt "
+ "to get the available geometry of a null widget");
+ desktop.availableGeometry((QWidget *)0);
QRect total;
QRect available;
@@ -158,6 +162,27 @@ void tst_QDesktopWidget::screenNumberForQPoint()
QVERIFY(screen >= 0 && screen < desktopWidget->numScreens());
}
+void tst_QDesktopWidget::screenGeometry()
+{
+ QDesktopWidget *desktopWidget = QApplication::desktop();
+ QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt "
+ "to get the screen geometry of a null widget");
+ QRect r = desktopWidget->screenGeometry((QWidget *)0);
+ QVERIFY(r.isNull());
+ QWidget widget;
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ r = desktopWidget->screenGeometry(&widget);
+
+ QRect total;
+ QRect available;
+ for (int i = 0; i < desktopWidget->screenCount(); ++i) {
+ total = desktopWidget->screenGeometry(i);
+ available = desktopWidget->availableGeometry(i);
+ }
+ QVERIFY(total.contains(r));
+}
+
QTEST_MAIN(tst_QDesktopWidget)
#include "tst_qdesktopwidget.moc"