summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 c8a4373..24b4e57 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 b9d9d7e..d846615 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"