Use static_cast rather than dynamic_cast

To avoid RTTI.
When I tried to implement the reconnect function in Plasma5,
I found that the application would have a dynamic_cast crash
problem. Referring to other usage logic and suggestions in Qt,
it is recommended to avoid using dynamic_cast.

Change-Id: I4fd41846c3215f60aafc7e38d1542d52ec6759b8
Reviewed-by: David Redondo <qt@david-redondo.de>
This commit is contained in:
Lu YaNing 2024-03-19 09:53:53 +08:00
parent 1d6cecbb4a
commit e89e8bf73f

View File

@ -454,13 +454,13 @@ void QWaylandDisplay::reconnect()
const auto windows = QGuiApplication::allWindows();
for (auto window : windows) {
if (auto waylandWindow = dynamic_cast<QWaylandWindow *>(window->handle()))
if (auto waylandWindow = static_cast<QWaylandWindow *>(window->handle()))
waylandWindow->closeChildPopups();
}
// Remove windows that do not need to be recreated and now closed popups
QList<QWaylandWindow *> recreateWindows;
for (auto window : std::as_const(windows)) {
auto waylandWindow = dynamic_cast<QWaylandWindow*>((window)->handle());
auto waylandWindow = static_cast<QWaylandWindow*>(window->handle());
if (waylandWindow && waylandWindow->wlSurface()) {
waylandWindow->reset();
recreateWindows.push_back(waylandWindow);