Commit Graph

71663 Commits

Author SHA1 Message Date
Marc Mutz 82cf1c0c16 QLineEdit: fix UB (invalid downcast) in Private::removeAction()
QLineEdit remembers whether a QWidget size-widget came from a
QWidgetAction or is just one of its own QLineEditIconButtons. On
removal of the action, if QWidgetAction, it will ask the action to
deal with its widget, calling QWidgetAction::releaseWidget(),
otherwise it just deletes the QLineEditIconButton itself.

This is fine if the action is being removed from the line edit, but
not immediately deleted. But if the action is being deleted while its
widget is still in a QLineEdit, then the QLineEdit is informed of this
only by ~QAction(), at which point the QWidgetAction has ceased to
exist and the cast, in QLineEditPrivate::removeAction(), to
QWidgetAction is UB.

Says UBSan:

  qlineedit_p.cpp:656:10: runtime error: downcast of address 0x6020000c3950 which does not point to an object of type 'QWidgetAction'
   0x6020000c3950: note: object is of type 'QAction'
    00 00 00 00  70 57 49 81 3d 7f 00 00  80 bc 0c 00 50 61 00 00  03 02 00 00 10 00 00 00  a6 01 00 71
                 ^~~~~~~~~~~~~~~~~~~~~~~
                 vptr for 'QAction'
    #0 0x7f3d93910686 in QLineEditPrivate::removeAction(QAction*) qlineedit_p.cpp:656
    #1 0x7f3d938b44bc in QLineEdit::event(QEvent*) qlineedit.cpp:1469
    #2 0x7f3d91c50211 in QApplicationPrivate::notify_helper(QObject*, QEvent*) qapplication.cpp:3309
    #3 0x7f3d91cd160a in QApplication::notify(QObject*, QEvent*) qapplication.cpp:3259
    #4 0x7f3d697f6ada in QCoreApplication::notifyInternal2(QObject*, QEvent*) qcoreapplication.cpp:1111
    #5 0x7f3d697f94e3 in QCoreApplication::sendEvent(QObject*, QEvent*) qcoreapplication.cpp:1551
    #6 0x7f3d92345199 in QWidget::removeAction(QAction*) qwidget.cpp:3215
    #7 0x7f3d92e47202 in QtWidgetsActionPrivate::destroy() qaction_widgets.cpp:35
    #8 0x7f3d7f75d5fb in QAction::~QAction() qaction.cpp:451
    #9 0x7f3d92e4cc76 in QWidgetAction::~QWidgetAction() qwidgetaction.cpp:94
    #10 0x7f3d92e4e965 in QWidgetAction::~QWidgetAction() qwidgetaction.cpp:94
    #11 0x558c993da3b0 in tst_QLineEdit::sideWidgets() tst_qlineedit.cpp:4693

To fix, check the dynamic type of the action (using qobject_cast)
before calling QWidgetAction::releaseWidget(). If the cast fails, the
QWidgetAction will have dealt with the widget itself, in its own dtor,
so QLineEdit needn't do anything.

Unfortunately, fixing this centrally by just dragging destroy() down
from ~QAction() to ~QWidgetAction() causes use-after-free in other
test functions of tst_QLineEdit, so I deciced to fix this at the
QLineEdit level only.

Amends 9ce12cc8de.

Pick-to: 6.8 6.5 5.15
Change-Id: I3c514dbd1f1a4e1510df3dd9ac67b4bab50e63e9
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit bf62a9762b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-03 05:33:06 +00:00
Marc Mutz 799237eaae tst_QTextEdit: fix UB (invalid downcast) in various functions
The test uses the old-but-invalid trick of inheriting from a class X
to gain access to its private or protected parts, but then just
casting an object of dynamic type X to the newly derived class. This
is invalid, because the object is not actually of the newly-derived
type.

Says UBSan (excerpt):

  tst_qtextedit.cpp:2273:5: runtime error: downcast of address 0x60400013c190 which does not point to an object of type 'PublicTextEdit'
  0x60400013c190: note: object is of type 'QTextEdit'
   00 00 00 00  70 bc 57 df b1 7f 00 00  80 66 30 00 90 61 00 00  70 be 57 df b1 7f 00 00  00 00 be be
                ^~~~~~~~~~~~~~~~~~~~~~~
                vptr for 'QTextEdit'

To fix, make QTextEdit befriend tst_QTextEdit. This is how we do it
elsewhere, too. Then remove the now-unused PublicTextEdit helper.

Amends the start of the public history, and, in one function,
56f0ebfe86 (which is only in Qt 6.4+, so
the cherry-pick to 5.15 will have to drop the part in pasteFromMarkdown().

Pick-to: 6.8 6.5 5.15
Change-Id: I967238d84cae0f6dd8f05d0afb7a318292d96415
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 73fc32af14)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-03 05:32:55 +00:00
Marc Mutz a8f7a100ae tst_QTextEdit: fix memleak in the MyPaintDevice helper
The constructor new'ed up a MyPaintEngine, but there was no destructor
to delete the object again. Neither is ownership of the engine
transferred out of the class, so the object was leaked.

Fix by holding it in a unique_ptr.

Amends 391e3aeef4.

Pick-to: 6.8 6.5 5.15
Change-Id: I0c4da10d5a1659eceac0deba32cac757579e46c5
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit de2de7e12c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-03 05:32:46 +00:00
Marc Mutz 414ca19a3f tst_QMetaType: fix UB (nullptr passed to memcmp()) in selfCompare()
QMetaType::Void is not constructible, so create() will return nullptr,
and even though sizeOf() returns 0, calling memcmp() is still UB in
that case.

Fix by guarding the memcmp() from QMetaType::Void.

Amends a59e736171.

Pick-to: 6.8 6.5
Change-Id: I55896826e6c0cad5d77e9d0ab861efa9a32f780f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit c6c2a0bf37)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-02 14:48:23 +00:00
Tim Blechmann 21b219f6b7 QLinuxFbIntegration: silence -Wunused-private-field
when configured without `evdev`, clang emits -Wunused-private-field

Pick-to: 6.8
Change-Id: Ia4ff59c002c1a00ef1b445520c28db0d932ee564
Reviewed-by: Liang Qi <liang.qi@qt.io>
(cherry picked from commit eb6042f915)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-02 02:21:05 +00:00
Ahmad Samir 5a73a80943 QCryptographicHash: use switch statements with the Algorithm enum
To benefit from -Wswitch compiler flag, requested by Marc in code
review.

Define supportsAlgorithm() twice, with/without USING_OPENSSL, amends
9248d0cfbe.

Change-Id: I236093532196689bc0828131360dfeeb24fac23f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 095e6fd084)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-02 01:12:09 +00:00
Christian Ehrlicher 1f5545e6f2 QSqlError: rename ctor parameter to 'nativeErrorCode'
Rename the parameter 'code' to 'nativeErrorCode' to match the getter
nativeErrorCode() with the ctor's parameters.

Pick-to: 6.8
Change-Id: Ic95b45c75a57796536d845249c719b5d0d0e7587
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 06ef995a7d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:07 +00:00
Christian Ehrlicher 3b175fbecc SQL/MySQL: use utc datetime in formatValue()
We store timestamps as utc in the database but QSqlDriver::formatValue()
does not format the datetime string as utc. Fix it by converting the
datetime object to utc first.
This amends 2781c3b624

Pick-to: 6.8
Fixes: QTBUG-135135
Change-Id: Id26b251e9ed9800d6caff7f43de25fd9e9b08f43
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 219e9fe7a2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:07 +00:00
Tor Arne Vestbø e98a2b90b9 Use QLastCursorPosition to check for missing cursor position
After c5792dcfd6 the last cursor position
is reflected as a QPoint(std::numeric_limits<int>::max(), ...), and
after 209a2145f9 as 1 << 23. Instead of
hard coding the sentinel value, let's use QLastCursorPosition directly.

Pick-to: 6.8 6.5
Change-Id: I24031f3cc800d2f0028eb95f4f8597019cc945c0
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 4ae41c225b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:06 +00:00
Christian Ehrlicher 424de984df Windows11Style: Honor sort indicator size in headerview
The windows11 style, in contrast to the windows vista style, draws the
indicator on the side. Therefore call QWindowsStyle::sizeHint() for
CT_HeaderSection as the base style has the correct implementation.

Pick-to: 6.8
Fixes: QTBUG-135338
Change-Id: If84f72f9f26e87617ecebb1a01f448219d8656ba
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
(cherry picked from commit 75c896f9b1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:06 +00:00
Volker Hilsheimer caa101c8e0 mac a11y: ignore expected debug output from test
Don't confuse the next person working on this code.

Pick-to: 6.8
Change-Id: I3f9ff59299a4150a96cc11d851d06539a5701a70
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 04fbdd2552)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:06 +00:00
Volker Hilsheimer f234dac1f9 Doc: remove stray 's'
Amends 4409edc14b.

Pick-to: 6.8
Change-Id: I1502e0d63a845c5deb476af1c37cb89a6cc43c6c
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
(cherry picked from commit 984074eea2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:06 +00:00
David Faure 8289d2e889 QTestLib: fix race on QElapsedTimers from WatchDog thread
The WatchDog thread calls printTestRunTime() which reads the two
timers, created and started in the main thread.

Pick-to: 6.8 6.5
Change-Id: I1a337648fddf87190075b7902311544d0ab21ac3
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 9e32306dae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 10:17:06 +00:00
Juha Vuolle 5ef7bf98a1 Yield a configuration error with -no-feature-desktopservices
Yield a configuration error with -no-feature-desktopservices
if the platform is either Apple or Android. This should be clearer
than a compiler error later on, and also occurs earlier in the
process.

Pick-to: 6.8
Fixes: QTBUG-135152
Change-Id: I5dfb9eda12472ed9359767f17423fda63d208d9c
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit b145f23770)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 06:25:21 +00:00
Juha Vuolle 3e67c1241a Put qxmlstreamreader code behind its feature-flag
Missed feature guards from:
- QXmlStreamReaderPrivate class declaration
- QXmlStreamWriter::writeCurrentToken definition [*]

[*] Function takes in a qxmlstreamreader. The declaration
of the function already had the necessary feature guard.

Pick-to: 6.8
Fixes: QTBUG-135230
Change-Id: I78741bc75a6baa8bc86ec5ce7d34a4333d8bdad4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit 90c90d5071)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 06:25:17 +00:00
Juha Vuolle 2cafab999d Fix qprocess.h include guards to match QProcess usage
Fixes: QTBUG-135225
Pick-to: 6.8
Change-Id: I64077ffaccc4f3b864c08df02b489857ac82f34b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 33df53bf32)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 06:25:14 +00:00
Eskil Abrahamsen Blomfeldt 3688d42011 Fix possible crash in FontConfig database
In the FontConfig font database, when we registered alternative
names for the same font, we would just copy the existing user
data (the FontFile struct) from the original font.

However, this did not account for the fact that registerFont()
may in some cases delete fonts from the database if they are
being overwritten, which will also delete the user data.
Therefore the existing FontFile struct is not guaranteed to
be valid once the font database has taken ownership.

This was pre-existing, but it started happening on some
systems after 1d6f71779f because
this change will cause some fonts to be seen as identical
which were not before.

Pick-to: 6.8
Fixes: QTBUG-135264
Change-Id: I913bf13dc8069d952a4cdc5fa5544594be1cdba1
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit 11620f97f6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-04-01 05:36:35 +00:00
Ahmad Samir 03ac8f8349 QDirIterator: next() should return empty string after reaching the end
Amends c7691842f7, and actually fixes the
other half of QTBUG-130142.

Fix the unittest, it was wrong to begin with, iterating over an empty
string with NoDotAndDotDot, next() will always return an empty string
because `currentFileInfo` has never been initialized.

Pick-to: 6.8
Fixes: QTBUG-135287
Task-number: QTBUG-130142
Change-Id: I9966428c7a143803e6e934b5970ea6b6afc8a08f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 4fd7d31e09)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 19:32:12 +00:00
Thiago Macieira f315104924 tst_QUuid: make big-endian runs not fail
As far as I can tell, QUuid is working correctly on big endian
platforms. But it stores the integers in such a weird fashion (I wish to
fix that for Qt 7) that this test is non-obvious.

I don't have a big-endian machine to test this with. Anyone interested
is welcome to submit patches.

Fixes: QTBUG-134634
Pick-to: 6.8
Change-Id: I2415be976d1d880d1525fffdf525dcf4f21aaa70
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit aa87214864)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 19:32:11 +00:00
Christian Ehrlicher deebbbba60 Tests/QSqlDriver: move cleanup tables into own function
Move the cleanup of the temporary tables into an own function and call them during init and cleanup. this makes sure the tables are
 - deleted on clean exit
 - not there during init when cleanup was not run (e.g. due to debugging or a crash).

Pick-to: 6.8
Change-Id: I9013a26b0166d0756a37f0a5d50ed825adf63868
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit c833ed5711)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 19:32:10 +00:00
Ivan Solovev cfda487726 QXmlStreamReader::addData: lock encoding for QLatin1 case
This fixes a bug when addData() is used to add a full Latin1-encoded
XML document with a proper "encoding" attribute.

Once addData() is called, it immediately converts the data to UTF-8.
However, if the encoding is not locked, the parser will later see
the "encoding" attribute, and try to interpret the data according
to the specified encoding.

The QXSR(QASV) constructor is not affected, because it already locks
the encoding.

Add a unit-test for the issue.

Amends 6bc227a06a.

[ChangeLog][QtCore][QXmlStreamReader] Fixed a bug when calling
addData() with a Latin1-encoded string containing a full XML document
with an encoding attribute, could result in incorrect parsing of this
document.

Fixes: QTBUG-135033
Pick-to: 6.8 6.5
Change-Id: I9a35d16d743050ea4feccab3d1336747ce0abff4
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 4b8659ebf6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 12:12:23 +00:00
Matthias Rauter 5405f6b575 Remove debug flag from benchmark
If debug symbols are needed, then pass the respective flag to the
configure script.

Pick-to: 6.8
Change-Id: I99db92bdd5b7eb896e0d592117a8f218467a4bd7
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 355e0d85eb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 12:12:23 +00:00
Frédéric Lefebvre 9b9bd00c2b Add QTestPrivate::ensurePositionTopLeft() for reliable positioning
Implement ensurePositionTopLeft() to set a window's position
to the available top-left corner and verify that it is correctly
positioned.

Incorrect updates to window.position and window.framePosition have
been identified as one of the main sources of flakiness on
Opensuse. This test function addresses this issue and improves test
reliablity.

Task-number: QTQAINFRA-7050
Change-Id: I946f74c7d2c1db9cfe4fec7db272e12876b3ed43
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 7929852c1d)
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2025-03-31 05:31:46 +00:00
Marc Mutz 7bf07cc12c tst_QGraphicsWidget: fix memleak in qgraphicswidget()
The QGraphicsWidget `parent` didn't have a parent itself, and the test
function neglected to delete the object manually, leaking it.

To fix, allocate it on the stack.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Ie9814655c1a52b6dc0d15076eca591fe710d51ae
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 76e76afb83)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:39:29 +00:00
Marc Mutz 8d99d38785 tst_QGraphicsWidget: remove unused object from qgraphicswidget()
The QGraphicsScene object wasn't used, so can be removed.

Make it so.

Seems to amend the start of the public history (and if there was a
user that has since been removed, we'll get a compile error, so no
need to data-mine the git history further).

Pick-to: 6.8 6.5 5.15
Change-Id: I9eeacde057ee5681ea86c185b66dff618a6f364e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 235fe36de7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:38:48 +00:00
Marc Mutz c57d487d9b tst_QGraphicsWidget: fix memleak in shortcutsDeletion()
The QGraphicsWidget didn't have a parent, and wasn't deleted by the
test function, so it leaked.

To fix, hold it in unique_ptr. While we're at it, and so that it
doesn't look too out of place, also hold the other parent-less
QGraphicsWidget in a unique_ptr.

The action, OTOH, has a parent, so we don't need to change something
there.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I0597b7ecd293ac54981df9e276c38c385ac811c7
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 92c1413c08)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:38:35 +00:00
Marc Mutz 604a76c8b3 tst_QGraphicsWidget: fix memleak in setStyle()
The result of QStyleFactory::create() is owned by the caller, and this
test function neglected to delete it, leaking the object.

To fix, reset() it, once created, into a unique_ptr. This is the
minimally0-invasive fix.

Amends 9bc49b0bca.

Pick-to: 6.8 6.5 5.15
Change-Id: I17fae174b93bd27e2cac6e5e2d2c8a4ac2de703e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit f0a9b5b6f1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:37:58 +00:00
Marc Mutz 08986f17f6 tst_QGraphicsWidget: remove unneeded casts in setStyle()
`fstyle` is already a QStyle*, so casting it to QStyle* is unneeded.

Amends 9bc49b0bca.

And 0 is a valid nullptr value, so we don't need to cast there,
either.

Amends the start of the public history.

Drive-by port to nullptr.

Pick-to: 6.8 6.5 5.15
Change-Id: If763b8bf42de9d8bbe988ac76773d02bb7a2b68b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit dbfcd54155)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:37:28 +00:00
Marc Mutz 4a9782f628 tst_QGraphicsWidget: fix memleak in implicitMouseGrabber()
If a QGraphicsItem is removed from a QGraphicsScene, it also gets
un-parent-ed, and the caller of removeItem() is responsible for
deleting the item henceforth. The test function neglected that,
leaking the object.

To fix, use a scope-guard to defer deletion of the object to the exit
from the test function. This is the minimally-invasive fix.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Ie4f9be232674bba583f4a59908e42de096930136
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 156bd55923)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:37:20 +00:00
Marc Mutz 6489fc1e52 tst_QGraphicsProxyWidget: fix memleak in forwardTouchEvent()
The result of QTest::createTouchDevice() needs to be deleted by the
caller. The test function didn't, so leaked the object.

Fix by holding it in unique_ptr.

Amends 982b70d37d, even though the code
that this patch replaced looked leaky, too.

Pick-to: 6.8 6.5 5.15
Change-Id: I3c7dfab31dc6ab364195381352d98fbd9c730990
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit bfd852c502)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:37:08 +00:00
Marc Mutz 02fb66f8a5 tst_QGraphicsProxyWidget: fix memleak in touchEventPropagation()
The result of QTest::createTouchDevice() needs to be deleted by the
caller. The test function didn't, so leaked the object.

Fix by holding it in unique_ptr.

Amends 1ecf2212fa.

Not picking to 5.15, because the cherry-pick of
1ecf2212fa to 5.15 was abandoned.

Pick-to: 6.8 6.5
Change-Id: I649357466a51e02d669b114bdfa0746bfa09fe34
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 01ee8fd7b5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:37:00 +00:00
Marc Mutz c1adc5c3ed tst_QGraphicsLinearLayout: fix memory leaks in removeAt()/removeItem()
Like in other test functions in this class, the QGraphicsWidgets were
leaked. So the solution is the same: hold them in a QVLA.

Also like in other test functions, the child layouts _are_ owned by
the parent layout, so were not leaked.

There's a twist here, though: we're removing layout items, which may
be widgets _or_ layouts. The old code deleted the removed layout item,
but we can't do that anymore, since it may be one of the widgets that
are owned by the QVLA, and that would cause a double-delete. If we
don't delete the removed item at all anymore, though, we'd leak it
when it was a layout.

So hold the layouts in QVLA, too. _Then_ we don't need to delete the
removed item anymore.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I16c61eb18f2843ceb72a432db1bd9be29e258bfd
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 0665ae81fb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:53 +00:00
Marc Mutz 97bacdaab3 tst_QGraphicsLinearLayout: remove remaining memleaks in insertItem()
After the QGraphicsWidgets have been dealt with in a previous commit,
the last leak in the function is that of 'item'.

Fix by holding it in a unique_ptr.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I56986139a2b7865cf367bdd25ccde90d5e1c50ca
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 59b18d07e7)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:45 +00:00
Marc Mutz fcf12e50c9 tst_QGraphicsLinearLayout: remove dead code (dump())
This test function hasn't tested anything since the start of the
public history, and leaks memory (the QGraphicsWidgets).

The dump() function, while implemented, doesn't do anything by default
(#ifdef'ed out), so there's no point in adding actual dump() calls
here, either.

Remove this function as dead code.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I6d9d224945fab0f97db0c5ea7d13a7df6c8837b2
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 8914732708)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:37 +00:00
Marc Mutz ceefdd6044 tst_QGraphicsLinearLayout: fix memleaks in count()/insertIrem()
The tests added parent-less QGraphicsWidgets to a
QGraphicsLinearLayout, which doesn't reparent them (and cannot,
because it doesn't have an item as a parent itself onto which to
reparent them), so the test functions leaked them.

The layout items, OTOH, do get reparented, and are therefore deleted
by the stack-allocated layout as its children.

Since there's thus no object that could naturally be a parent for the
widget items, allocate them on the stack. Since their number is
variable, use QVLA, whose constructor is able to create a ... wait for
it ... VLA of non-copyable-non-movable elements on the stack (we test
for this, also in Qt 5, see e7c792ba71).

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: I9b0b65efbccd1fd7e708da4d12f746d942f602fe
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 374b9fd031)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:30 +00:00
Marc Mutz a961848c16 tst_QGraphicsLinearLayout: fix memleaks in itemAt()
The old code used a data-driven test to check that itemAt(i), 0 ≤ i ≤
2, was returning non-nullptr. It re-created the widgets and the layout
for each data tag anew, leaking the widgets by the way.

Using data-driven test machinery here is overkill. Remove it and
create the widgets in a C array on the stack, so they're not leaked,
and iterate over them using range-for.

Also check not just for nullptr, but also that the pointer matches the
widgets we put into layout, at the position we put them in.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Ib808aa6756c6550a61a4768edfc5021f2f6ae3b3
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 159029b587)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:24 +00:00
Marc Mutz c144326b2d tst_QGraphicsLinearLayout: fix memleaks in defaultSpacing()
QStyle objects aren't owned by widgets (or QGraphicsWidgets) they are
set on, so need to be deleted manually. The test function didn't do
that, so they style objects were leaked.

To fix, hold them in unique_ptrs. QStyle subclasses, even though being
QObjects, don't have the usual QObject *parent=nullptr constructor
parameter, so passing a QObject parent isn't an alternative, really.

Amends 66b7e7497c.

Pick-to: 6.8 6.5 5.15
Change-Id: I6c43264760f7126610fe51f72e74ec341bd2e3d7
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit dd9a94a3b3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:17 +00:00
Marc Mutz d25185fb0d tst_QGraphicsLinearLayout: fix memleaks in itemAt_visualOrder()
The test function leaked all the items it created.

Unless I renamed the object and kept the pointers to them by their old
names, any fix would touch every line, anyway. The former would be
pretty contrived in such a short function, so port the complete test
to stack-allocated objects, which is how this function would have been
written today.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Ia8a67825d3a80be4574b7779c2105d53003b9e69
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 64060cbeae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:10 +00:00
Marc Mutz 25b71e1fee tst_QGraphicsLinearLayout: fix memleak in testStretch()
QGraphicsView, being a QWidget, needs to have a parent or be manually
deleted. The test function did neither, so leaked the view.

Fix by allocating it on the stack.

Amends 913ff73200.

Pick-to: 6.8 6.5 5.15
Change-Id: If012d4b833849285b62e2a4b4089457c2aef1d88
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 9bab38b133)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:36:02 +00:00
Marc Mutz 30fe30550f tst_QGraphicsLayout: fix memleaks in alternativeLayoutItems()
I honestly didn't bother to figure out the ownership relationships
between these items; the QGraphicsView docs don't help much:

> The layout takes ownership of the items. In some cases when the
> layout item also inherits from QGraphicsItem (such as
> QGraphicsWidget) there will be a ambiguity in ownership because the
> layout item belongs to two ownership hierarchies

but asan said that the AnimatedLayoutItem objects were leaked, so hold
them in unique_ptrs now.

Amends the start of the public history.

Pick-to: 6.8 6.5 5.15
Change-Id: Icd0eabc4129b57251bbec7f8e3752f99ee584cf3
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit f3a02fe39d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:35:54 +00:00
Marc Mutz b15d1ee499 tst_QSplitter: don't leak the QSplitter from initTestCase()
Several test functions use a centrally-allocated QSplitter for their
tests. This object was allocated in initTestCase(), but
cleanTestCase(), while present, was empty, so nothing deleted the
object again.

Fix by deleting the object in cleanupTestCase(). Initialize the member
variable to nullptr so that the delete is well-formed even if
initTestCase() for some reason didn't run (or didn't run to
completion).

Amends the start of the public history, where this function read

    #if defined(QT3_SUPPORT)
        delete qApp->mainWidget();
    #endif

which was already leaking if QT3_SUPPORT wasn't defined.

Pick-to: 6.8 6.5 5.15
Change-Id: I43e5d8921a9c097f252e11709f25bc622fc8fe15
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit fbaa376335)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:35:47 +00:00
Marc Mutz b9fd0b1272 tst_QSplitter: fix memleak in replaceWidget()
Depending on whether QSplitter::replaceWidget() succeeds or not, we
need to delete either the return value (an unparented QWidget) or the
argument (another QWidget without parent). The test function only
deleted the return value.

Use a unique_ptr for delayed automatic deletion at the end of the test
function, which is the minimally-invasive fix. Use it for both
candidates, which ensures that either one of them is reliably deleted,
even if a QCOMPARE() fails in-between.

One check before we reset(newWidget) is special: if (!res) fails, then
the reaper contained something we also need to delete, and the reset()
will do that, but code checkers (e.g. Coverity) are known to complain
about using a pointer value after a delete, so split the check into
the check and the QVERIFY().

Amends 2c634a1326.

Pick-to: 6.8 6.5 5.15
Change-Id: I8571477d9e53b85b2db041d7c9bdf2bd7aa69906
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 4513d48490)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-31 04:35:38 +00:00
Magdalena Stojek 64fd9edb2c Clarify QDomProcessingInstruction docs regarding XML declaration
The documentation now explicitly explains that the XML declaration is
not a processing instruction according to the XML 1.0 Specification and
the W3C DOM Level 1/2 Core specifications. It advises against using
createProcessingInstruction() to insert an XML declaration and
recommends QXmlStreamWriter.
This clarification aims to reduce confusion caused by the similar syntax
of processing instructions and the XML declaration.

Fixes: QTBUG-21166
Pick-to: 6.8 6.5
Change-Id: I630e0e73bc8e4b6f145cb1e771a0a6fec54543cf
Reviewed-by: Safiyyah Moosa <safiyyah.moosa@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit d2258328e3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-30 16:07:30 +00:00
Thiago Macieira 013793a783 QThread/Doc: improve docs on running, finished, and the OS thread
And take the opportunity to explain that the finished() signal does not
indicate the end of the operating system thread. Indeed, on some OSes,
not even wait() can be sure of that: for Unix systems, see the docs at
the top of qthread_unix.cpp about timed pthread_joins.

Pick-to: 6.8
Fixes: QTBUG-135163
Change-Id: Ie00a742f0707f57c767bfffd44bdaec40df05e4a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
(cherry picked from commit de90f2e064)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-30 13:01:41 +00:00
Thiago Macieira f2b58861d2 QRhiD3D11: fix qHash() to use qHashMulti()
The old code used XOR to combine hash values, but XOR is a bad combiner,
since it's mixing the bits insufficiently (XORing the same value again
will e.g. undo the original change).

This is a private class, so there are no users outside of Qt that would
have inlined this qHash() function; therefore, we are free to change the
algorithm.

Change-Id: I7970e52ef4bd3b6a2248fffda0d4d75eb4afdf5a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 7bf9beb300)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-30 13:01:39 +00:00
Thiago Macieira db33112d4d forkfd: fix build with FreeBSD 14.2: convertForkfdWaitFlagsToWaitFlags()
The FreeBSD-specific pdfork() code in forkfd_freebsd.c code was failing
to build because convertForkfdWaitFlagsToWaitFlags() wasn't
defined. That function is behind a check for #ifdef HAVE_WAITID, which
is only defined if _POSIX_VERSION is 2008 or later. That macro has been
stuck at 2001 for the past 23 years. I can't explain how this code
compiled with FreeBSD 14.1 and earlier, because I am sure it was using
pdfork().

So just #define HAVE_WAITID for FreeBSD. It must have been there since
much earlier than 13.0, but that seems like a reasonable starting point
today.

We also need to #include <sys/param.h> to have the __FreeBSD_version__
macro, something that also wasn't needed in earlier versions. It was
probably indirectly #include'd by something.

Pick-to: 6.8
Change-Id: I262d9922128d046221b7fffd0ec481bc0012f55c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
(cherry picked from commit 729a6f56d0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-30 13:01:38 +00:00
Thiago Macieira 7de18b1467 QFileSystemEngine/Unix: deduplicate the st_mode parsing
Both fillFromStatBuf() and fillFromStatxBuf() had copies of the parsing
of the st_mode / stx_mode field. This deduplicates them and sets up for
when/if other OSes get a statx() system call similar to Linux's.

Change-Id: I7c80d121c21b76d78b81fffd172d205287b595d9
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit e86b970ea4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-30 13:01:37 +00:00
Shawn Rutledge 9e59a924a0 QTextMarkdownImporter: Fix heap-buffer-overflow
After finding the end marker `---`, the code expected more characters
beyond: typically at least a trailing newline. But QStringView::sliced()
crashes if asked for a substring that starts at or beyond the end.

Now it's restructured into a separate splitFrontMatter() function, and
we're stricter, tolerating only `---\n` or `---\r\n` as marker lines.
So the code is easier to prove correct, and we don't need to check
characters between the end of the marker and the end of the line
(to allow inadvertent whitespace, for example). If the markers are
not valid, the Markdown parser will see them as thematic breaks,
as it would have done if we were not extracting the Front Matter
beforehand.

Amends e10c9b5c0f and
bffddc6a99

Credit to OSS-Fuzz which found this as issue 42533775.

[ChangeLog][QtGui][Text] Fixed a heap buffer overflow in
QTextMarkdownImporter. The first marker for Front Matter
must begin at the first character of a Markdown document,
and both markers must be exactly ---\n or ---\r\n.

Done-with: Marc Mutz <marc.mutz@qt.io>
Fixes: QTBUG-135284
Pick-to: 6.8
Change-Id: I66412d21ecc0c4eabde443d70865ed2abad86d89
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 2598674694)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit eced22d725)
2025-03-28 22:49:53 +00:00
Edward Welbourne b546ab5af4 Purge dangling uses of QDateTime deprecated time-spec changes
QDateTime::{to,set}TimeSpec and QTimeZone::setOffsetFromUtc()
shouldn't be referenced in docs aside from their own; they are
deprecated from 6.9.

Fixes: QTBUG-135238
Pick-to: 6.9.0 6.8
Change-Id: I835cfaa888dd3079f96719cd1c413dc7c2796fdb
Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 8c943392ae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-28 16:32:24 +00:00
Axel Spoerl 75663be3b5 QXdgDesktopPortalTheme: Refactor base theme creation loop
The search for a base theme was handled in 2 separate loops.
Combine those in sync with QGuiApplication.
Make list of theme names const, as it doesn't and mustn't change.

Pick-to: 6.8 6.5
Task-number: QTBUG-134702
Change-Id: If4ae8212bbefa2934639feec983b94e8e2d6b168
Reviewed-by: Jan Grulich <jgrulich@redhat.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 63ba867ddd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-03-28 16:32:23 +00:00