From c5792dcfd631abb4f9e2b92cd6e88d7e5c373406 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 1 Feb 2022 07:56:23 +0100 Subject: Make QGuiApplicationPrivate::lastCursorPosition.toPoint() safe to use QGuiApplicationPrivate::lastCursorPosition is initialized with qInf(); so before Qt has seen a mouse move event, attempting to convert to QPoint is an error. It's best to have one place where we do the qIsInf() check rather than several (and otherwise prefer using the QPointF as-is rather than converting to QPoint at all). Introduce a helper class that contains a QPointF, and provides a safe conversion to QPoint, as well as simple accessors for clients using QPointF. Fixes: QTBUG-52472 Task-number: QTBUG-45045 Change-Id: I83fad1bfb658e03fa876344552f1d5bb751d9f81 Pick-to: 6.2 6.3 Reviewed-by: Marc Mutz Reviewed-by: Shawn Rutledge --- src/widgets/kernel/qwidgetwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/kernel/qwidgetwindow.cpp') diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 14a2655e35..88818ce9c5 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -402,7 +402,7 @@ void QWidgetWindow::handleEnterLeaveEvent(QEvent *event) QWindowSystemInterfacePrivate::EnterEvent *systemEvent = static_cast (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter)); - const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QGuiApplicationPrivate::lastCursorPosition; + const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QPointF(QGuiApplicationPrivate::lastCursorPosition); if (systemEvent) { if (QWidgetWindow *enterWindow = qobject_cast(systemEvent->enter)) { -- cgit v1.2.3