Utils: Fix crash on showing tooltips when screen configuration changed

Check QGuiApplication::screenAt(QPoint) return value. TextTip will use
QGuiApplication::primaryScreen() if it's nullptr.

Fixes: QTCREATORBUG-25747
Change-Id: If02648966e24f96f8c9a92e91b2bd27c1efc5f9e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Mikhail Khachayants
2021-05-17 13:31:41 +03:00
parent 5b828f84fb
commit 2c2a3a9bef

View File

@@ -206,7 +206,12 @@ void TextTip::configure(const QPoint &pos)
// Try to find a nice width without unnecessary wrapping.
setWordWrap(false);
int tipWidth = sizeHint().width();
const int screenWidth = QGuiApplication::screenAt(pos)->availableGeometry().width();
QScreen *screen = QGuiApplication::screenAt(pos);
if (!screen)
screen = QGuiApplication::primaryScreen();
const int screenWidth = screen->availableGeometry().width();
const int maxDesiredWidth = int(screenWidth * .5);
if (tipWidth > maxDesiredWidth) {
setWordWrap(true);