Commit Graph

75625 Commits

Author SHA1 Message Date
Tor Arne Vestbø 24fb55b236 tst_QImage: Resolve image format name via QDebug::toBytes()
Instead of manual mapping, which also had slight differences in how
the formats were expressed, making it confusing.

Change-Id: Ie92b9315f22b36a82908d31f62483e315a509e83
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-21 18:22:45 +02:00
Zhao Yuhang 104ec33523 Windows QPA: make theme code more robust
WinRT APIs may throw in some cases (real cases reported
 by our customers), let's wrap WinRT calls in try catch to
avoid app crash.

As a drive-by, move the accent color handling in populateDarkSystemBasePalette
 out of the try-catch block due to it has been handled already in
 qt_accentColor(), also remove some color entries which
 are not used.

Change-Id: Ibdd9b9b7d93ebc8218a127e1f9a8e73f5d1332a5
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
2025-08-21 16:22:45 +00:00
Alexandru Croitor 1f1a34f6be CMake: Conditionally generate SPDX fields if value is not given
Otherwise the file will not be valid.

Pick-to: 6.8 6.9 6.10
Task-number: QTBUG-134894
Change-Id: Ib5b94d24cfac1c11b8c4608872155a080b1e4f89
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-08-21 16:26:01 +02:00
Alexandru Croitor ecf1e021de CMake: Fix some policy CMP0174 warnings during SBOM generation
We should only forward arguments to cmake_parse_arguments options
that actually have values.

Pick-to: 6.8 6.9 6.10
Task-number: QTBUG-134894
Change-Id: I0e2eecc4c87378ee3c2eb44f693288c8c58f2d21
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-08-21 16:26:01 +02:00
Alexandru Croitor 253a7f95bc CMake: Don't use private CMake API in doc snippets
Private CMake API like qt_internal_extend_target should not be used in
public doc snippets. While most of the CMakeLists.txt doc snippets
might not appear in the documentation right now, they might in the
future (just like the CMake API doc snippets).

In addition, using private CMake API for doc snippets targets causes
issues with SBOM generation, because the original targets are not
created with private API (e.g. qt_internal_add_module vs
qt_add_library), and thus important sbom meta information is missing,
causing errors at cmake configure time when sbom generation is
enabled.

Pick-to: 6.8 6.9 6.10
Change-Id: I2ef80f617ba8b745520408d22dd2e6be5ee4c5e0
Reviewed-by: Oleksii Zbykovskyi <Oleksii.Zbykovskyi@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2025-08-21 16:26:00 +02:00
David Boddie 2ce6fd48e0 Doc: Fix broken "see also" links
Pick-to: 6.9 6.10
Change-Id: Iff6f5642c6c26e7e99533e2f56554a286fccdbb3
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2025-08-21 14:08:30 +00:00
Volker Hilsheimer 313e271c73 QRM: don't emit warnings in release builds
Remove code printing qCritical/qWarning messages from release builds
(of the the code using QRangeModel, as this is all in the template).

Pick-to: 6.10
Change-Id: I9bdcd2134c4d11740994d5eb1c5a2d217a3d9fde
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
2025-08-21 13:57:51 +02:00
Artem Dyomin 1bc470a6fc QRM: implement quasi-virtual logic in a separate class
- use type-safe calls
  (before the patch, mess of args/ret types leads to UB).
- encapsualte all the logic of callFN init and and
  calls propagation in QQuasiVirtualInterface/xxxSubclass
- get rid of operation enums, use typed method aliases instead.
- the logic can be reused in other qt elements
- decreases binary size on the user size. On macOS build:
  tst_qrangemodel: got 171696B (5%) decrease, 3361600B => 3189904B.
  Most likely, it's because of the replacement of 2 call funcs with 1.
- insignificantly decreases binary size of QtCore.

Pick-to: 6.10
Change-Id: Ib961611adf7bb179985b9e27254839ce05425406
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-21 13:57:50 +02:00
BogDan Vatra 51d04d0917 Don't assert if the QFuture is in pending state
Same as result/results takeResult should just waitForResult

Fixes: QTBUG-139119
Pick-to: 6.10 6.9 6.8
Change-Id: Ic578ee6c5853a5b1551f1d30ac9f5e302f79b4e6
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-08-21 12:00:37 +03:00
Tero Heikkinen 5bd9267af7 Win ARM: Blacklist tst_QRhiWidget::grabFramebufferWhileStillInvisible
Also for cross-compile target for Windows on ARM
  - windows-11_23h2-arm64-msvc2022
  - windows-11-x86_64-arm64-tests-23H2 (cross-compile)

Task-number: QTBUG-138249
Task-number: QTBUG-138252
Pick-to: 6.10 6.9
Change-Id: I20eca89ad99bc8491232c3f51a1d9023903570ac
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
2025-08-21 07:23:32 +03:00
Liu Zheng b40086e008 UBSan build failure by replacing QThreadPrivate usage
Replace private QThreadData::get2() API calls with public Qt APIs
to resolve undefined symbol references when building with UBSan.

The issue occurred because QThreadPrivate symbols are not exported
in non-developer builds, causing link failures with UBSan enabled.
This fix maintains the same thread safety validation while using
only public APIs:

Fixes: QTBUG-123404
Change-Id: Ie73ac47246302f133367f2cd7cab5d8f77f0cfcb
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: David Edmundson <davidedmundson@kde.org>
2025-08-21 12:20:30 +08:00
Marc Mutz 28449e220f QMessageLogger: drop inline keyword from noDebug() out-of-body definition
Out-of-body definitions of inline functions should not have an inline
keyword themselves, because it's superfluous and can hide problems
(like the declaration not being marked as inline, which often trips up
MinGW; without the inline keyword on the definition, such errors are
caught on all platforms at link time).

Amends 4fa44a70bc.

Pick-to: 6.10
Change-Id: I2039c8b3c430835406a7711ff0319d161d6c5cbb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-08-21 05:55:53 +02:00
Axel Spoerl ad5417c2b4 Make QWindowContainer::containedWindow() invokable
QWindowContainer is a private class.
Applications might need to obtain the QWindow pointer of the contained
Window, in case it has been dynamically added.
Squish is one possible use case.

Make containedWindow() invokable, so it can be obtained via
introspection.

Change-Id: I308b9b23f2d8bea4eb16baf7850d64dc870f59bd
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Stefan Gehn <stefan.gehn@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-21 03:43:26 +02:00
Marc Mutz f49ba1a6ec qvsnprintf: port from qt_saturate to q26::saturate_cast
The latter isn't in Qt 6.5 to which the amended commit was picked, so
we used the old name qt_saturate there. This patch ports to the new
name.

Amends the commit that fixed QTBUG-138860 (final SHA-1 not known at
this point).

Task-number: QTBUG-138860
Pick-to: 6.10 6.9 6.8
Change-Id: Ia84ae50ddfd18cf028ecc7461821f4e727f0009a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-08-20 21:40:24 +02:00
Oleksii Zbykovskyi 46b8f2eb1a Widgets snippets: Use the header file instead of a new class each time
In several snippets, the TableModel class is created and used.
I included a header file to avoid code repetition.

Change-Id: Ie6318606cc89a2f5f1c137a36195fe290b6c1be6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-20 20:15:46 +02:00
Richard Moe Gustavsen ae6f389942 QMacStyle: fall back to draw QProgressBar manually on macOS Tahoe 26
On macOS Tahoe 26, the drawing of a QProgressBar using the mac
style is broken. Nothing is drawn if we continue to use
[NSView drawRect:], [NSView bitmapImageRepForCachingDisplayInRect:]
or [CALayer renderInContext:] (and similar API) for drawing
an NSProgressIndicator.

This patch will therefore implement a fall back approach where
we draw the QProgressBar manually when we detect that the current
version of macOS is running with liquid glass support.

Pick-to: 6.10 6.9 6.8 6.5
Fixes: QTBUG-138947
Task-number: QTBUG-138942
Change-Id: Idab450ea1598f7a46fece68c7e3d07f21569cfbb
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2025-08-20 19:54:14 +02:00
David Boddie b5ed961273 Doc: Remove spurious characters
Pick-to: 6.10
Change-Id: Ibfd907bf8ea80063cb896d2ba36cfd2a2ebfa241
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2025-08-20 19:54:14 +02:00
Mate Barany 16c6797273 Add example snippet to QNetworkInformation::isMetered()
Highlight only the important part.

Task-number: QTBUG-136625
Pick-to: 6.10
Change-Id: I9707d0d69b964421ab4f8a07c8b87cc07fa01e2f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-08-20 18:37:28 +02:00
Mate Barany 380ed8d487 Add simple example how to test for connectivity with QNetworkinfo
Extended with a description that explains the shortcomings of this
approach.

Task-number: QTBUG-136625
Pick-to: 6.10
Change-Id: I07473b1395fcc6dec0917da4bcc1c3791c1ed839
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-08-20 18:37:28 +02:00
David Boddie 0543158533 Doc: Fix "see also" link
Pick-to: 6.9 6.10
Change-Id: Ib0dea34c435d48e8d2188bbdd7492d5fd20d738e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2025-08-20 16:34:19 +02:00
Tim Blechmann 05df96967e Cocoa: make headers self-contained
Clang-based IDEs like QtCreator try to parse the headers in isolation
and warn if some types are not defined.
Including the required headers makes the codebase more robust.

Task-number: QTCREATORBUG-33334
Pick-to: 6.10
Change-Id: I7819d0ca947a7c857a49d85ce3076d4e965afa72
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2025-08-20 22:34:19 +08:00
Tim Blechmann 2331d6e353 Cocoa: add tracing to removeFromSuperview
QNSView has tracing for all reparenting methods except for
removeFromSuperview. Adding it helps a bit with debugging.

Pick-to: 6.10
Change-Id: Ib3443431b30b5a25b5743ae1b10bf9ac95471e4d
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2025-08-20 14:34:18 +00:00
Alexey Edelev 238400b22f Introduce UseToolchainFromTargetDir feature for tests that are built at test stage
The feature allows controlling which toolchain should be used when
building tests. Since WoA supposed to build tests using the
crosscompiled Qt in native host environment, this option allows
preparing the correct build environment and use the crosscompiled
'target' Qt.

Drive-by change the way prefix.bat is called for native WoA configuration.

Pick-to: 6.10
Change-Id: Ifec7593b4216ee2e2ffe185ae0dc0559d501762b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2025-08-20 16:34:18 +02:00
Alexey Edelev 26e0396381 Avoid hardcoding the crosscompilation requirements when building WoA
Pick-to: 6.10
Change-Id: Id725bb5ab404d9fb7f644896434ae1afc4ca4ef2
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2025-08-20 16:34:18 +02:00
Alexey Edelev 4f44f43332 Consider cross compilation when detecting host tools requirements
If Qt is crosscompiled it's not necessary that it always require host
tools to compile the application. That's why the pre-stored assumpion
in Qt6Dependencies.cmake is incorrect. When moving the Qt toolchain
to the target platform, this Qt becomes the native toolchain for this
platform, so the requirement is incorrect since this moment.

The detection should consider the CMAKE_CROSSCOMPILING flag and put
the host tools requirement only in this case. Also if user predefined
QT_HOST_TOOLS it also makes sense to require them and look for the
Qt6HostInfo package.

Pick-to: 6.10
Change-Id: I4c715eb2592ce79565787645aac172ff60b91493
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2025-08-20 16:34:18 +02:00
Eskil Abrahamsen Blomfeldt 5992945869 Upgrade Harfbuzz to 11.4.1
[ChangeLog][Third-Party Code] Upgraded Harfbuzz to version
11.4.1.

Pick-to: 5.15 6.5 6.5.10 6.8 6.9 6.10
Task-number: QTBUG-139288
Change-Id: Iae118af070490a048870c70459b1f59851c4bafa
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2025-08-20 16:34:18 +02:00
Allan Sandfeld Jensen e13f11bba7 Handle top-level Tool windows
Undo most Qt::Tool and Qt::Popup overlap, and keep just basic logic of
dealing with transientsParents and positioning.

Amends 4eba0b5305

Pick-to: 6.10
Fixes: QTBUG-139250
Change-Id: I0ea4275740f41b54f0604fced86ec828919c3ae7
Reviewed-by: David Edmundson <davidedmundson@kde.org>
2025-08-20 13:44:46 +02:00
Tasuku Suzuki 1c26d20b3f Fix QRegion ifdef inconsistencies
Remove unnecessary platform guards that caused inconsistencies between
header and implementation files:

1. Remove dead code for operator+=(const QRect&) that was guarded by
   #if !defined(Q_OS_UNIX) && !defined(Q_OS_WIN)
   This condition is never true since all platforms define either
   Q_OS_UNIX or Q_OS_WIN. Even if such an environment existed,
   this fallback implementation would work, but the build would fail
   anyway due to missing implementations of QRegionPrivate and core
   constructors that are incorrectly guarded by the opposite condition.

2. Remove #if defined(Q_OS_UNIX) || defined(Q_OS_WIN) guard around
   QRegionPrivate and related implementations (lines 1066-4320).
   This condition is always true, but the header file declares these
   unconditionally. If this guard were false, it would cause linker
   errors for all QRegion constructors and methods.

These changes ensure header and implementation files are consistent
and eliminate dead code.

Pick-to: 6.10 6.9 6.8
Change-Id: Ibd3caddfd68273a091b11d0a40909d0e44eb6947
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2025-08-20 10:24:56 +00:00
Marc Mutz 7a1e7c88f0 QQuaternion: fix SiC in fromEulerAngles() overload set
Before ba21e89c2f, fromEulerAngles({-90,
0, 0}) would call the QVector3D overload of fromEulerAngles(). After
said commit, the call was ambiguous, because the unnamed braced
initialization could init a QVector3D as well as a
QQuaternion::EulerAngles.

While this is technically allowed, because unnamed braced initializer
arguments don't enjoy SC protection (otherwise a user passing {} would
block any overload being added), we can, as Fabian pointed out, fix
the SiC in this case by marking the QVector3D overload as
Q_WEAK_OVERLOAD. We need to mark the old one, because that one is only
conditionally available and because we want to default to the newer
API.

This changes the mangling of the function, which matters because this
non-polymorphic class is needlessly exported (though pre-programmed to
not be anymore in Qt 7), so we need to switch the Q_WEAK_OVERLOAD on
and off for removed_api.cpp to maintain BC.

Move the definition of the function into the class body because we
don't have a Q_WEAK_OVERLOAD_IMPL to slap in front of the out-of-body
definition.

Amends ba21e89c2f.

[ChangeLog][QtGui][QQuaternion] Added fromEulerAngles() overload
taking the new EulerAngles struct as an argument.

Done-with: Fabian Kosmale <fabian.kosmale@qt.io>
Task-number: QTBUG-138199
Change-Id: I64481b017073fb01e9a023e5dd47c8c66d4dcafc
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-20 10:24:55 +00:00
Marc Mutz 9bddf611fb Revert^2 "QQuaternion: long live EulerAngles / eulerAngles()"
This reverts commit 35cdc0cb83.

Reason for revert: The original change was correct. Users can't expect
SC if they pass untyped braced initializers to Qt functions. If we had
to maintain SC for such calls, we could never add new overloads
(someone could pass `{}`, after all). This is similar to taking the
address of a Qt function: you have no protection if you don't cast to
a particular type of function pointer.

Task-number: QTBUG-138199
Change-Id: Ice1f40cbd2bc0fbd97a11aa8d72580f1225db9fb
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-20 12:24:55 +02:00
Marc Mutz a31a8da004 QString: fix unintended copy in asprintf() return
On GCC, this function is NRVO'd, but depending on the definition of
va_list, a compiler may be unable to NRVO this function, in which case
the const on 's' prevents the implicit return by move.

Found by Coverity.

Fix by dropping the const. It doesn't hurt readability in such a short
function, shuts up Coverity, and may improve codegen on some
platforms.

Amends d251cae7b7.

Coverity-Id: 474158
Pick-to: 6.10 6.9 6.8
Change-Id: I4f842f690ea45c8db4c02f32f858d2700f57d128
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 11:44:29 +02:00
Marc Mutz eaeeb6b5d3 QXmlStream: don't use Structured Bindings
Decoder::operator() already returns a proper struct with named
members, so decomposing that using SB can do no good, except
introducing a dependency on the order of the struct, which is
counter-productive.

Fix by receiving the result in a proper variable and using the
struct's member names.

Amends 53622aca2a.

The idea may have been to avoid churning the surrounding code, but
follow-up c08766abf2 touched all
lines using the result, anyway, so we don't need SB anymore to
keep the old names.

Pick-to: 6.10
Change-Id: I2890754c2c2189cc2fa395f4500ca6c3cb115d7d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 11:44:28 +02:00
Marc Mutz 37f774c4e9 QByteArray/QString: fix a few unintended copies
In reallocData() and reallocGrowData(), when we create a completely
new QArrayDataPointer, we merely copy-assigned it to this->d in the
end. This needlessly ups and downs the atomic ref-count, so use a
swap() instead.

Found by Coverity, which wants us to use std::move(), but I believe
the QtCore maintainer would prefer the swap here, so use "C++98 move".

Amends
- 20041afe3b QByteArray::reallocData()
- 287ace562e QString::reallocData()
- 4b9ec00534 QByteArray::reallocGrowData()
- a2b1b0292d QString::reallocGrowData()

Pick-to: 6.10 6.9 6.8
Coverity-Id: 425077
Coverity-Id: 425941
Coverity-Id: 426231
Coverity-Id: 427184
Change-Id: I037f38c6541068b91b55343a20f149a772ba79c0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 11:44:28 +02:00
Marc Mutz ed35893745 qvsnprintf: fail if the result size doesn't fit into an int
The old code silently truncated the return value of the fallback
implementation. This is dangerous, as the caller might rely on the
truncated value to confirm that everything was written when it
actually wasn't, incl. trusting the return value to allocate a buffer
of a size dependent on the result and then strcpy()ing the data over
(which would overflow the target buffer, since the NUL byte is
actually at `n` and not at `result`, as the function post-condition
would require for a result < n.

POSIX specifies¹ that errno be set to EOVERFLOW and -1 be returned, so
do that.

As a drive-by, replace use of qMin() with std::min() (which statically
asserts that both arguments are of the same type, unlike qMin(), which
performs integral promotion on the arguments).

Use qt_saturate() for now, because 6.5 doesn't have
q26::saturate_cast(). A follow-up patch will clean this up for
6.8...dev.

[ChangeLog][QtCore][q(v)snprintf] Fixed a bug that would cause
q(v)snprintf() to report success on some platforms, even though the
result was truncated.

Amends the port of Qt containers from int to qsizetype. Didn't check
for a particular commit, because a) it's probably several that apply
and b) they are so much older than the currently active branches that
I didn't feel I need to be more specific than, essentially, "Qt 6.0".

¹ https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html

Fixes: QTBUG-138860
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I6de8a99c238539a535462e964a0645bd0c704fff
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-08-20 11:44:28 +02:00
Jonathan Clark 184ec7cad2 QTextEngine: Pass expanded context to HarfBuzz for shaping
Previously, when laying out text using harfbuzz-ng, QTextEngine would
only populate the HarfBuzz buffer with the substring associated with a
single item at a time - in effect, semantically breaking the string at
format boundaries. While this approach doesn't have obvious effects for
some languages, it can make text illegible in languages that have
different character forms depending on word position (such as Arabic).

This change updates QTextEngine to instead pass the full string to
HarfBuzz. By doing so, HarfBuzz can inspect the contents of the string
around the current item, and substitute the correct characters at the
item boundaries.

Note that this change isn't a complete fix for QTBUG-54350. In
particular, ligatures will not form across item boundaries, which may
cause incorrect text rendering in some situations. However, this fix
should address some of the more painful cases, such as label mnemonics
breaking Arabic text rendering.

[ChangeLog][Text] Improved text shaping with mnemonics
in certain languages, such as Arabic.

Pick-to: 6.10
Fixes: QTBUG-93371
Change-Id: I3639e50b809269836cd5480609d22328f9deaf82
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2025-08-20 06:51:01 +02:00
Lu YaNing 051f116818 tests: buffer overflow warning in wayland reconnect test
The display_name buffer size was insufficient for the maximum possible
output of snprintf with format "wayland-%d". The compiler warned that
output could be 10-20 bytes but the destination buffer was only 16 bytes.

Increase buffer size from 16 to 32 bytes to accommodate the worst case
scenario (e.g., "wayland--2147483647") and provide safety margin.

Change-Id: Id980a0d897f06d1a0c1f2cb2afba9f6cd36c2988
Reviewed-by: David Edmundson <davidedmundson@kde.org>
2025-08-20 11:47:55 +08:00
Thiago Macieira 038d127fe5 QChar::isSpace: optimize by lowering the upper limit check
Of all the Category categories, separators are the only to currently
have assigned codepoints exclusively in the BMP. This allows us to lower
the maximum check from the LastValidCodepoint to category-specific
one. This will also cause the compiler to dead-code eliminate the check
inside of qGetProperty and emit only the BMP check of the property
tables:

    if (ucs4 < 0x11000)
        return uc_properties + uc_property_trie[uc_property_trie[ucs4 >> 5] + (ucs4 & 0x1f)];

Pick-to: 6.10
Change-Id: I31eda5d79cc2c3560d90fffd74a546d1e7cda7bb
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-19 18:04:55 -07:00
Marc Mutz 5b1e49a7e2 QLocale: fix unintended copy [2/2]: QCalendarBackend::dateTimeToString()
Coverity complained that 'text' was copied when it could have been
moved.

This is correct, but not trivial to understand: If, in a ternary
expression, one of the legs is an rvalue and the other is an lvalue,
then the ternary expression is also an rvalue. So the return statement
invokes the QString move constructor.

But, of course, the lvalue isn't being moved from in this case.
Instead, lvalue-to-rvalue conversion materializes a temporary QString
as a copy of lvalue, and _that_ is moved instead. This is what happens
with 'text' and why Coverity complains about a copy.

Note that this is purely due to the use of the ternary: If we write a
normal if, then the lvalue leg returns a local object and we get a
move from it for free. In fact, the structure of the lambda is such
that NRVO should kick in, so neither copy nor move, but direct
construction into the caller-supplied storage of the return object.

To fix, rewrite the code using a normal if statement, taking care to
not break the NRVO the rest of the function so carefully tries to
maintain.

This likely also fixes CID-469957 where Coverity complains that this
lambda's implicit auto return type causes a copy and - incorrectly!
- suggests to explicitly return const QString& (which would return a
reference to a local object).

Amends 1b909695a6.

Coverity-Id: 469949
Coverity-Id: 469957
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: Ia858fd6bddbb51d824b29b0e60d26c18c1c7fb5d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-19 22:47:30 +00:00
Marc Mutz cd96362492 QLocale: fix unintended copy [1/2]: rawStandaloneMonthName()
Coverity complained that 'name' was copied when it could have been
moved.

This is correct, but not trivial to understand: If, in a ternary
expression, one of the legs is an rvalue and the other is an lvalue,
then the ternary expression is also an rvalue. So the return statement
invokes the QString move constructor.

But, of course, the lvalue isn't being moved from in this case.
Instead, lvalue-to-rvalue conversion materializes a temporary QString
as a copy of lvalue, and _that_ is moved instead. This is what happens
with 'name' and why Coverity complains about a copy.

Note that this is purely due to the use of the ternary: If we write a
normal if, then the lvalue leg returns a local object and we get a
move from it for free (NRVO isn't possible, because it's not
statically known which of the two possible objects will be returned.

To fix, rewrite the code using normal a normal if statement.

Amends aa8393c94f.

Coverity-Id: 425487
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: Ia85346afc50d8a2a1abf8a5f079280c787cd964a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 00:47:30 +02:00
Marc Mutz 4bef66d2dc QCalendarLocale: move switch over QLocale::FormatType into accessors
Before, each user of QCalendarLocale was performing the switch by
themselves. Even though there was only one user each of month and
standalone month, their switch statements were buried in larger
functions and contained a default case label with the return from the
surrounding function. The default was necessary, because running off
the end of the switch was normal operation, but it destroys -Wswitch.

Instead of wrapping the switch in a lambda, realize that these
switches were also the only users of the fine-grained accessors of
QCalendarLocale and move the would-be lambda there as a member
function. This means we now have functions containing only one switch
each, so we can return from each case label and falling off the end of
the switch statement is unreachable. This removes the need for a
default case label, re-enabling -Wswitch. It also allows to mark the
DataRange objects const in the callers.

Found as part of fixing Coverity issue 425487.

Amends aa8393c94f.

Coverity-Id: 425487
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: If1dd16f11b96372f00dc4469fd6b12f835bc7877
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 00:47:30 +02:00
Marc Mutz efc4b92bb0 tst_QQuaternion: add some more Euler angle tests
In particular, `xonly-opposite` is there to verify that a replacement
of a static const QQuaternion::fromEulerAngles(-90, 0, 0) in QQuick3D
(which is a runtime initialization because fromEulerAngles() isn't
constexpr) with a direct constructor call (which is a compile-time
constant) is equivalent.

The others are for symmetry.

Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I20236d7b43680611daa298c5a3266179dd2d2167
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 00:47:30 +02:00
Marc Mutz 85f998577b qTzName(): fix -ftrivial-auto-var-init=pattern performance regression
We don't need the compiler to write half a KiB of stack memory here,
so add the opt-out macro.

Amends 9ff1e6d80b.

Pick-to: 6.10 6.9 6.8
Change-Id: I0138bf30b451bbfeaa20582298f5cadaa85a938f
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-20 00:47:30 +02:00
Marc Mutz 22362a7f36 qTzName(): eliminate some code duplication
Commit f6f68d5f8d brought the function
into a form where the _UCRT and non-_UCRT paths share a common prefix
and suffix (the establishing and ending of the critical section).

This commit takes advantage of the new form to extract the common
affixes from the platform-dependent sections, avoiding repetition.

Amends said commit.

Pick-to: 6.10 6.9 6.8
Change-Id: I562bfdfa0a64861003d3a5de85ba3be878e24184
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2025-08-20 00:47:30 +02:00
Marc Mutz 220055176e qTzName(): fix UB (calling strlen(nullptr))
Coverity complained that that we're calling strlen() before checking
its argument for nullptr. Calling strlen(nullptr) is UB, so guard the
call manually.

An alternative would be to use qstrlen(), which can explicitly handle
nullptr, but this is very low-level code, so we should probably stick
to the bare metal here.

Amends f6f68d5f8d.

Pick-to: 6.10 6.9 6.8
Coverity-Id: 487584
Change-Id: I8301f47179d80234408711af5f95563320bd590c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2025-08-20 00:47:30 +02:00
Christian Ehrlicher 0b75d08ef1 Windows11Style: Simplify call to buttonLabelColor()
Make buttonLabelColor() a non-static member function so we don't need to
pass the colorSchemeIndex and the helper function winUI3Color() can be
called directly.

Pick-to: 6.10 6.9
Change-Id: Ifa2a8ff9b70ee00493b194fbcbe33225f6ca3b54
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
2025-08-19 21:16:03 +02:00
Christian Ehrlicher 1abad9a30e Windows11Style: remove double painting for PanelButton
When fillBrush() was added, the then unneeded painting routing to draw
the fill of a PanelButton was not removed which resulted in a wrong
double painting.
This amends b3c0b08eb0.

Pick-to: 6.10 6.9 6.8
Change-Id: If9322f97d8632b8114dbe73c44d276511d3d82b3
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
2025-08-19 21:16:03 +02:00
Ahmad Samir b81aded649 Add normalizeTypeInternal() overload with an out QBA parameter
Useful when called in a loop from QMetaObject::normalizedSignature();
avoids allocating a QByteArray for each type in a method's signature.

Drive by, add missing include.

Change-Id: I423a618f79df2db2be859d41e5df1150b6da9b79
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-08-19 22:16:03 +03:00
Oleksii Zbykovskyi 3bf4a0f14e Widget snippets: Fix indentation in qtreewidget-using example
Made minor adjustments to the indentation in the qtreewidget-using
example to ensure clarity and consistency in the code snippets.

At the same time, combine snippets 10 and 11 because they are only used
together. Updated related documentation to reflect these changes.

Amends 1cf7d9f34f

Change-Id: I7446341cf4e498004199c1ec9d08e31df9ae5b7f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-19 21:10:09 +02:00
Oleksii Zbykovskyi b5056dfe3f Create a header file for MainWindow class
MainWindow class was created and used all around widgets snippets.
I made a seperated header file for all of these cases to avoid
repetitive code.

Change-Id: Ic403fc7d5278f77e62d8b5265c4184a154fef1b6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2025-08-19 21:10:09 +02:00
Thiago Macieira f0019c5139 QTest::qWaitFor*: capture the widget/window using QPointer
So we know if they get deleted before the waiting completes. This avoids
a crash if we dereference a dangling pointer or an ABA coincidence in
the case of qWaitForWindowFocused.

There's currently no way to tell QTest::qWaitFor() that the condition
will never become true, so this will result in a timeout.

[ChangeLog][QtTest] Fixed a bug that would cause the qWaitForWindow* and
qWaitForWidget* functions to crash or misbehave if the window or widget
they were told to wait on was destroyed in the process of waiting for it
to be shown/focused/activated/exposed.

Pick-to: 6.10 6.9 6.8
Task-number: QTBUG-136653
Change-Id: Idaef89fa55e869d6946afffd727653a1fee3770c
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-08-19 11:10:13 -07:00