Commit Graph

15845 Commits

Author SHA1 Message Date
Thiago Macieira
f4101f9953 QString/QBA: add lvalue and rvalue overloads to first/last/sliced/chopped
Those ought to have been the original implementation, when they were
added in commit 38096a3d70, for Qt 6.0.

Because these classes are exported, we need to provide the previous only
implementations for MSVC. All other compilers would provide inline or
emit local, out-of-line copies.

Change-Id: Ifeb6206a9fa04424964bfffd178836a2ae56157d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-25 12:01:58 -07:00
Thiago Macieira
2fd0996324 QArrayDataPointer: add an allocating constructor
It's by far the most common use, so having to call two things is just
cumbersome.

Change-Id: I79e700614d034281bf55fffd178f454c4e31929e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-25 12:01:58 -07:00
Edward Welbourne
887e18990d tst_QLocale: base europeanTimeZone test on 2013, actually used in test
The test that needs this bool is using 2013, so test that year for a
match. (Africa/Tunis toyed with DST in 1990, the year used before, but
thought better of it.) In the process, move the initialization to the
member-initialization of the class and make the member const.

Change-Id: Ib87636cdb0b038fad0cdef9fbe49e96f7bf79d1f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-25 18:32:06 +02:00
Morten Sørvig
fde6bdfc5a wasm: add QIODevices for accessing JS data
BlobIoDevice: Supports reading data from a JS Blob,
which can be a File (on disk) or some other object
which can provide data. The native access functions
are async and using this class requires that asyncify
is available.

Uint8ArrayIODevice: Supports reading and writing to
a Uint8Array / ArrayBuffer. Similar to the existing
QByteArray::fromEcmaUint8Array() API, except that it
supports incremental accesss.

Change-Id: Ic5de3534ff75eb6c745287b73b15ccd92d74ac2c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2023-10-25 17:56:55 +02:00
Volker Hilsheimer
342b37f388 Revert "QAtomic: remove the copy ctor and assignment operator"
This reverts commit 6a93ec2435.

Reason for revert: Breaks qtdeclarative build, submodules need
to be clean before we deprecate or remove APIs.

Change-Id: Id0726b9bfad6072065b380b44b6ff6dffda79e45
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-10-25 15:56:54 +00:00
Tor Arne Vestbø
1af821825a macOS: Fix tst_MacGui::nonModalOrder()
The test is testing whether the order of creating a child window
of a modal dialog and showing the parent dialog matters. But to
allow child windows of a modal dialog to become active that child
also needs to be a dialog. That's a limitation on macOS, where
only NSPanel subclasses can override worksWhenModal.

Fix the test, and rewrite it using more modern idioms, avoiding
the need for long waits in the test.

Pick-to: 6.6 6.5
Change-Id: Ifb640d0288a3c7ed37f2c61294e34cd96fba49ca
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-10-25 17:41:32 +02:00
André Klitzing
fd9c567156 Use SSL_CTX_set_dh_auto if DHparam is empty
[ChangeLog][QtNetwork][QSslDiffieHellmanParameters] An empty
Diffie-Hellmann parameter enables auto selection of openssl
backend.

Fixes: QTBUG-117666
Change-Id: Ic2e0529d48542752ca801bcb4d609988e5ddff25
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-25 17:23:13 +02:00
Giuseppe D'Angelo
6a93ec2435 QAtomic: remove the copy ctor and assignment operator
These special member functions have no purpose.

We never *documented* their semantics. Any code using them is
unconditionally wrong (which semantics was it assuming?), so we can
accept the SIC (type A). If a user needs such a copy, they would have to
reason on the intended semantics (relaxed? acquire/release?) and be
explicit in their code. Especially for assignment, they would need
understand the consequences of the memory ordering that apply on _each_
atomic object involved and not on the assignment operation as a whole
(there are no such semantics).

Testing this change on qtbase has already found bugs.

From a purely technical point of view: we don't guarantee lock-free
atomics nor we require them from the underlying platform. An atomic is
therefore allowed to be implemented as a mutex protecting a value, and
mutexes are not copiable. std::atomic follows the exactly same pattern
(not copiable nor copy-assignable) for exactly the same reasons, and Qt
atomics are implemented on top of std:: ones.

[ChangeLog][QtCore] The copy constructor and assignment operators of
Qt atomic classes (QAtomicInteger, QAtomicPointer) have been removed.
Their usage in user code should be considered a programming error, as no
memory ordering semantics were ever documented for these operations (and
therefore relying on any specific semantic would be relying on
undocumented, unportable behavior). This matches the API of the
std::atomic class in C++. Note that you can still use explicit
load/store operations to transfer a value across two Qt atomic objects,
and therefore use the memory ordering specified for the load/store
operations.

Change-Id: Iab653bad761afb8b3e3b6a967ece7b28713aa944
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-25 04:47:47 +02:00
Ahmad Samir
e1dcc858b2 QStringList: improve benchmark code
Make the strings in the stringlist-to-be-joined unique, which matches
actual use-cases better than joining a list of identical strings,
especially with QString's implicit sharing, if it's copies of the same
QString, it's sharing the underlying data.

Pick-to: 6.6 6.5 6.2 5.15
Task-number: QTBUG-116859
Change-Id: I1da93885e938045322ba8337df5e4e96985f892f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-25 03:19:20 +03:00
Mårten Nordheim
13fbedd162 QStringConverter[win]: expose+test control of code-page
Then we can easily test how fromLocal8Bit() and toLocal8Bit() behave
with different code-pages.

Pick-to: 6.6 6.5
Task-number: QTBUG-118318
Task-number: QTBUG-118185
Task-number: QTBUG-105105
Change-Id: Ib1cd3bccd27d598f4c80915557e332befcd96354
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-24 22:30:03 +02:00
Thiago Macieira
a61d752951 tst_QHashFunctions: suppress warning about casting from float to _Float16
Amends c86cf385d6.

tst_qhashfunctions.cpp:109:59: warning: converting to ‘qfloat16::NativeType’ {aka ‘_Float16’} from ‘float’ with greater conversion rank

Pick-to: 6.6 6.5
Change-Id: I79e700614d034281bf55fffd178f91775966658f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-10-24 08:44:36 -07:00
Ahmad Samir
ceee7acf43 qcore_unix: port qt_safe_poll to QDeadlineTimer
Remove qt_poll_msecs() since the "forever" state can be simply expressed
with a QDeadlineTimer::Forever arg, instead of passing a nullptr
timespec, and the negative timeouts treated as "run forever" is also
encapsulated by QDealineTimer.

Use the QDealineTimer(qint64) constructor in the call sites where
the timeout could be negative, so that it creates a Forever timer (the
QDeadlineTimer(chrono::duration) constructor uses
setRemainingTime(duration) which handles negative timeouts by creating
expired timers).

Remove qt_gettime() (and do_gettime()).

Drive-by changes:
- Fix a narrowing conversion warning, qt_make_pollfd() takes an int
- Remove an unused include

Change-Id: I096319af5e191e28c3d39295fb1aafe9d69841e6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-24 18:29:45 +03:00
Volker Hilsheimer
89f0f34db5 tst_QSslSocket: Remove compile-time #ifdef check
Since we use runtime plugins now and the test doesn't use any
symbols from openssl

Amends 486b1aec16

Pick-to: 6.6 6.5
Change-Id: Ib66d1ca15835c41fe138c7830ce3edd0bdce0d5f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-23 18:00:52 +02:00
Edward Welbourne
51cfc973b3 Add a QDateTimeEdit::timeZone property
This shall ultimately replace its timeSpec property, which had already
been turned into a derived property of an internal timezone.

[ChangeLog][QWidget][QDateTimeEdit] Added timeZone property to enable
a datetime edit widget to control the timezone used. This makes the
timeSpec property redundant; this old property shall be deprecated
from 6.10.

Fixes: QTBUG-80417
Change-Id: I3cdb686bd2dada0e5067f5b4c1828b73892e424a
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-10-23 18:00:52 +02:00
Volker Hilsheimer
72ad419116 JNI: Fix reference leak in QJniArray
When the array type is QJniObject or a subclass, then we need to
explicitly release the local reference returned by GetObjectArrayElement
in the QJniArray::at implementation. Do this by constructing the
QJniObject via fromLocalRef, which does exactly that.
Amends 80d4d55e25.

Add a test case that stresses the local reference pool, and fix the old
test case (which operates on a QJniArray<jobject>) to also release the
local references.

Change-Id: Ie293b1db9f1b6825376bbf12338b22dfc3f8c6e9
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-23 15:10:28 +02:00
Øystein Heskestad
fd48ce0b73 Add support for containers > 4 Gi elements in QDataStream
The format is changed from 6.7 to support more than UINT32_MAX - 1
elements. The format used to have a quint32 size. Now if the size is
larger or equal to 0xfffffffe (2^32 -2) the old size is an extend
value 0xfffffffe followed by one quint64 with the actual value. The
32 bit size with all bits set is still used as null value.

Fixes: QTBUG-105034
Change-Id: I62188be170fe779022ad58ab84a54b1eaf46e5d9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-23 15:10:28 +02:00
Laszlo Agocs
0d413506a1 Skip Vulkan on Android in QRhi autotest
Fixes: QTBUG-118220
Change-Id: I78b4b8b85f316f087ab7a01c1ee0c4fad46c632a
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-23 12:33:56 +00:00
Ahmad Samir
f2e19d37de QStringList: add lastIndexOf() overloads
[ChangeLog][QtCore][QStringList] Added lastIndexOf() overloads that take
a QString/QStringView/QLatin1StringView and a Qt::CaseSenitivity
parameters. Prior to this calling lastIndexOf() would call the methods
inherited from the base class. This change is source compatible and
existing code should continue to work.

Task-number: QTBUG-116918
Change-Id: Ia50c884c00021bf581c23c12e0e0c22700dae446
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-22 14:37:57 +03:00
Ahmad Samir
c205f05128 QStringList: add filter(QL1SV) overload
[ChangeLog][QtCore][QStringList] Added filter(QLatin1StringView)
overload, which is more optimized when searching for a Latin-1 string
literal as no conversion to QString is necessary.

Task-number: QTBUG-116918
Change-Id: Ieb92f4cfd545b070258dbc5c701ddfb2e6f3fc64
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-22 14:37:52 +03:00
Ahmad Samir
3dffd5aa0b QStringList: add indexOf() QString/QStringView/QL1SV overloads
[ChangeLog][QtCore][QStringList] Added indexOf() overloads that take
QString/QStringView/QLatin1StringView, and a Qt::CaseSensitivity
parameter. Prior to this using QStringList::indexOf() called the methods
inherited from the base class.

Task-number: QTBUG-116918
Change-Id: Ibc42130b6509f6ecfe7de0d6be378f226ae61982
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-22 14:37:47 +03:00
Ahmad Samir
a6ad755734 QStringList: add filter(QStringMatcher) overload
Now that users can pass a QStringMatcher to do the matching, change the
existing overload to not use QStringMatcher.

Thanks to Giuseppe D'Angelo for the idea of passing a QStringMatcher to
filter instead of using a magic number to decide whether to use
QStringMatcher or not.

Results of running filter() and filter_stringMatcher, times are in msecs
and this was compiled with gcc -O3:

              Without       With QStringMatcher
list10        0.00022       0.000089
list20        0.00040       0.00014
list30        0.00058       0.00018
list40        0.000770      0.00023
list50        0.00094       0.00027
list70        0.0012        0.00037
list80        0.0014        0.00041
list100       0.0018        0.00050
list300       0.0054        0.0014
list500       0.0091        0.0023
list700       0.012         0.0032
list900       0.016         0.0041
list10000     0.17          0.045

Drive-by change: optimize tst_QStringList::populateList().

[ChangeLog][QtCore][QStringList] Added filter(const QStringMatcher &)
overload, which may be faster for large lists and/or lists with very
long strings.

[ChangeLog][Possible Performance Changes][QtCore][QStringList] Changed
the implementation of filter(QStringView) overload to not use
QStringMatcher by default. Using QStringMatcher adds overhead, so it is
beneficial/faster when searching for a pattern in large lists and/or
lists with long strings, otherwise using plain string comparison is
faster. If using QStringMatcher makes a difference in your code, you can
use the newly added filter(QStringMatcher) overload.

Change-Id: I7bb1262706d673f0ce0d9b7699f03c995ce28677
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-22 14:37:33 +03:00
Thiago Macieira
3e330a79ec QStorageInfo/Linux: rewrite the label retriever to use device IDs
Instead of the previous realpath() comparison resulting from the symlink
processing. parseMountInfo() was extracting the device number from
/proc, so this information was already readily available.

We must take care of anonymous block devices (major == 0). Certain
filesystems, such as btrfs, always use them, so we must still stat() the
device path to get the real block device.

This implementation assumes that udev only creates entries in the
/dev/disks/by-label directory that are symlinks to real devices, but
that must already be the case because they are in /dev in the first
place. An alternative implementation would be to compare the inode and
host device (st_dev) of the entry, if different /dev entries could have
different labels. I don't think that's possible. But multiple /dev
entries for the same device is definitely possible.

Pick-to: 6.6
Change-Id: I9d43e5b91eb142d6945cfffd1787552af3d09676
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-10-21 15:21:24 -07:00
Thiago Macieira
9df2b7ffa4 tst_QStorageInfo: make storageList() test table-driven
Otherwise we have no way of knowing which QStorageInfo entry was being
tested.

Previous:
FAIL!  : tst_QStorageInfo::storageList() 'other.isValid()' returned FALSE. ()

Now:
FAIL!  : tst_QStorageInfo::storageList(/run/user/0/gvfs) 'other.isValid()' returned FALSE. ()

Change-Id: I8f3ce163ccc5408cac39fffd178d786e596ece81
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-21 15:21:19 -07:00
Tor Arne Vestbø
70d7c6a937 Avoid creating child windows twice when already visible
When a child window is made visible without its parent having been
created yet, we defer creating and making the child visible until
the parent is created.

But if a child window is explicitly created, we create the parent
first. And creating the parent will in turn apply visibility to
all children that had their visibility deferred. Which includes
creating the child.

This results in child -> parent -> child creation recursion,
which means that when we return from creating the parent window
we already have a platform window for our child, and should
bail out.

Pick-to: 6.6 6.5
Change-Id: I11dc4864b57f031de2cca70b79cdfc057d4fbd0d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-21 19:23:12 +02:00
Ahmad Samir
341854a4f3 QStringMatcher: add a method that returns a string view of the pattern
The existing pattern() method always returns a QString, which means that
if the matcher was constructed using a QStringView, pattern() would
uncoditionally convert it to a QString.

This is useful to check if a match is exact:
auto pattern = matcher.patternView();
if (pattern.size() == needle.size() && matcher.indexIn(needle) == 0)
    ....

This may be needed for a later change in QStringList::contains();
regardless of that, this change makes sense on its own.

Change-Id: I49018551dd22a8f88cf6b9f878a5166902a26f58
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-21 16:50:16 +03:00
Volker Hilsheimer
66b5803ab9 Adapt QRawFont to use QFont::Tag
Add an overload for fontTable (we can't deprecate the const char *
overload as it will be used for string literals, even if the tag-
overload would work), and use the tag type in the test instead of
QByteArray.

Task-number: QTBUG-117046
Change-Id: I104f11a25e9c453a5d1081b6cf320bdc186b7e80
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2023-10-20 21:37:15 +02:00
Volker Hilsheimer
61ceff89f7 Replace MAKE_TAG macro with QFont::Tag
Task-number: QTBUG-117046
Change-Id: I26e0af634fed87199bb49d57e3aa3f4e3fea0e39
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2023-10-20 21:37:02 +02:00
Volker Hilsheimer
bde443801f QFont: add a tag type for features and other advanced properties
Instead of overloads and generic string literals with runtime checks,
use a dedicated Tag type for specifying the font feature. The Tag type
can only be instantiated with a string literal of exactly 4 characters
(plus the terminating null)l; longer or shorter literals result in a
compile time error.

Constructing a Tag from any other string type is possible through the
named fromString constructor, in which case we can only check the length
and warn at runtime.

The type's API is almost completely constexpr so that we can use it to
calculate e.g. enum values.

Task-number: QTBUG-117046
Change-Id: I31038c7c6fd2b843a105b032f021e506b0b60822
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2023-10-20 21:36:52 +02:00
Mårten Nordheim
486b1aec16 tst_QSslSocket: remove #if openssl check for a definition
The declaration was moved out of the #if QT_CONFIG(openssl) block at
some point, but the definition was not. This caused compilation errors
when building without OpenSSL configured.

Pick-to: 6.6 6.5
Change-Id: I41ed85fd57f5a912498e0f2517761b81a7b8673c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-10-20 20:08:20 +02:00
Assam Boudjelthia
028a31b505 Android: remove unneeded allowNativeHeapPointerTagging manifest flag
Amends b0907db9eae4b85fcab4fa997428c438d9443ee0.

Pick-to: 6.5 6.6
Task-number: QTBUG-91150
Change-Id: Ic7886a9fc69781e4f21417075516106ccb6c7bf5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-10-20 18:46:29 +03:00
Edward Welbourne
e72a898c50 Clarify the behavior of QDateTime around 24-hour transitions
For those that simply repeat or skip a whole calendar day, life is
fairly simple. However, Alaska's 24-hour transition at 15:30 LMT Sitka
(incidentally combined with a change of calendar) is a bit trickier.
Also fix a typo I noticed in passing.

Write tests to determine what the actual behavior is and document
enough to make the actual behavior seem unsurprising once encountered,
without trying to go into all the excruciating details. Naturally, MS
time-zone data lacks the data on the historic transitions involved in
these tests, so MS (when not using ICU's time-zone data) is excluded.
It seems Cupertino believes Alaska was always in the USA, too.

Change-Id: Ia638c04d2ffc3a956a70a2a85badb7bbfdbb791c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-19 14:45:56 +02:00
Edward Welbourne
a49ccc08c3 QDateTime: disambiguate times in a zone transition
Previously, requesting a time that got repeated - on the given date,
due to a fall-back transition - would get one of the two repeats,
giving the caller (no hint that there was a choice and) no way to
select the other. Add a flags parameter that captures the available
ways to resolve such ambiguity or select a suitable time near a gap.

Add such a parameter to relevant QDateTime methods, including
constructors, to enable callers to indicate their preference in the
same way. This replaces DST-hint parameters in various internal
functions, including QTimeZonePrivate's dataForLocalTime(). Adapted
tst_QDateTime to test the new feature.

Adapt to gap-times no longer being invalid (by default; or, when they
are, no longer having a useful toMSecsSinceEpoch() value). Instead,
they don't match what was asked for. Amend documentation to reflect
that. Most of the code change for this is to QDTParser and QDTEdit.

[ChangeLog][QtCore][QDateTime] Added a TransitionResolution parameter
to various QDateTime methods to enable the caller to indicate, when
the indicated datetime falls in a time-zone transition, which side of
the transition to fall or whether to produce an invalid result.

[ChangeLog][QtCore][Possibly Significant Behavior Change] When
QDateTime is instantiated for a combination of date and time that was
skipped, by local time or a time-zone, for example during a
spring-forward DST transition, the result is no longer marked invalid.
Whether the selected nearby date-time is before or after the skipped
interval may have changed on some platforms; unless overridden by an
explicit TransitionResolution, it is now a date-time as long after the
previous day's noon as a naive reading of the requested date and time
would expect. This was the prior behavior at least on Linux.

Fixes: QTBUG-79923
Change-Id: I11d5339abef9e7125c4e0dc95a09a7cd4f169dab
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-19 14:45:56 +02:00
Marc Mutz
38994ab9ac tst_QMetaEnum: add round-trip testing to valueToKeys()
... adding a bit of test coverage of keysToValue().

This is not intended as a reproducer for QTBUG-118240, because that
is concerned with inputs valueToKeys() cannot produce.

Task-number: QTBUG-118240
Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I5d772be4231717cdbb5d033b1f11ae31e4c57c0b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-10-19 12:22:42 +00:00
Mitch Curtis
18152699e4 Increase QTest failure message limit
QPalette specifically has quite a large amount of output (1363
characters) when toString
is called on it. We should make sure that we can fit that in our
failure messages. This patch does that by increasing the limit from
1024 characters to 4096.

Fixes: QTBUG-5903
Fixes: QTBUG-87039
Pick-to: 6.5 6.6
Change-Id: I1dc5078ad05858bb6542c3a06c6b84711af79e4f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-19 10:57:21 +08:00
Thiago Macieira
a3f2ddc230 tst_QProcess::startStopStartStopBuffers: depend less on OS configuration
The comment in this function made it clear that it really depended on
the size of the pipe buffer in the OS. I don't see a way to make a pipe
default to a different size on Linux -- it always defaults to
PIPE_DEF_BUFFERS (16) and that value is only increased as a result of
fcntl(F_SETPIPE_SZ), which we don't do. But we can be defensive and
simply write until the OS can't take any more data.

Drive-by update the comment on Windows to be clear that bytesToWrite()
does work, but only while the child process is still running.

Pick-to: 6.6
Task-number: QTBUG-80953
Change-Id: I9d43e5b91eb142d6945cfffd17866d22a4127e5e
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-10-18 12:40:54 -07:00
Ahmad Samir
5a2aa12147 tst_qdbusmarshall: disambiguate unittest data tag names
Drive-by change, initialize a QList with std::initializer list instead
of old style operator()<<.

Change-Id: If5745a4554772661df438e757518f8cb55a8a55c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-10-18 20:53:12 +03:00
Thiago Macieira
d3edc8a62d tst_QStorageInfo::{tempFile,caching}: change APFS from XFAIL to SKIP
Amends commit 78d0b6e975 ("Ignore failing
test for free space on APFS") and merges it with the btrfs code, which
seems to have the same problem. But unlike Linux systems with btrfs,
Apple systems don't usually have another filesystem available so we
don't bother to try and find another.

Change-Id: I8f3ce163ccc5408cac39fffd178d7b4c13f0dfd1
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2023-10-18 10:01:45 -07:00
Thiago Macieira
ae03ffaffd tst_QStorageInfo::{tempFile,caching}: try a to find a non-btrfs storage
These tests skip when we're writing to a btrfs filesystem because, for
some reason, the amount of free space does not update synchronously with
file writing. But instead of giving up if $TMPDIR is a btrfs, let's try
and use the $XDG_RUNTIME_DIR, which is usually a tmpfs.

This will work in the CI for the openSUSE set ups, where / is btrfs,
/tmp is not a separate tmpfs, but /run/user/1000 is available.

FAIL!  : tst_QStorageInfo::tempFile() The computed value is expected to be different from the baseline, but is not
   Computed (free)                : 25510780928
   Baseline (storage2.bytesFree()): 25510780928
   Loc: [tst_qstorageinfo.cpp(234)]

Pick-to: 6.6
Change-Id: I8f3ce163ccc5408cac39fffd178d7af1c67ec988
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-18 10:01:45 -07:00
Mikolaj Boc
0607c25f3e Make WASM IDB settings use the fallback mechanism correctly
Change-Id: Ibb65efc0faa5ec6e6c60782747c9295e4fc5ff21
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2023-10-18 19:01:45 +02:00
Ahmad Samir
8a6a9295eb tst_QStringList: refactor a unittest to be table-driven
Change-Id: I9a102a42eba42f1bec71cc680f6de6dbeaf7ad58
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-18 20:01:45 +03:00
Volker Hilsheimer
944200b5a9 JNI: Reduce amount of temporary QJniEnvironment instantiations
Almost all operations on a QJniObject require a QJniEnvironment,
including the construction and destruction of a QJniObject. Instead of
instantiating a temporary QJniEnvironment object in each call, store the
one from the constructor in the private, and reuse it.

Pass the stored environment through to other functions needing it, and
add a checkAndClearExceptions() wrapper.

Static class members still need their own QJniEnvironment, but we can
reuse the one we have to get both jclass and jmethodID rather than
creating new QJniEnvironments in several wrappers.

As a drive-by, clean up nullptr usage in the test that failed when
shortcutting isSameObject for the trivial cases.

Change-Id: Ibadbd2be8a0ec9ab62daf285608ee7fe0a3c8852
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-18 15:02:22 +02:00
Volker Hilsheimer
b7a7351767 JNI: treat equivalent C++ types as the same JNI types as well
Our signature mapping treats both e.g. bool and jboolean as "Z", and it
is allowed to pass a bool variable as an argument to a function expecting
a jboolean. Except for fields and callMethod return values, where we only
allowed the JNI primitive types.

Fix this by comparing the signatures and size of the type we have with
the JNI types that there are explicit functions for. Cast from and to
the JNI type in both directions to address narrowing (e.g. jboolean is an
unsigned char and converting to bool would be narrowing, even though
both are 8bit types).

This way we can get boolean fields using getField<bool>, and int fields
using getField<int> etc.

Change-Id: I2f1ba855ee01423e79ba999dfb9d86f4b98b1402
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-18 15:02:22 +02:00
Thiago Macieira
c94bed69b7 moveToTrash/Unix: refactor to use openat()/mkdirat()/renameat()
This ensures much better security against race conditions and attacks,
at the expense of a few more system calls.

On first run (when no trash dir is yet present):

  openat(AT_FDCWD, "/home/tjmaciei/.qttest/share/Trash", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
  mkdirat(AT_FDCWD, "/home/tjmaciei/.qttest/share/Trash", 0700) = 0
  openat(AT_FDCWD, "/home/tjmaciei/.qttest/share/Trash", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 5
  newfstatat(5, "", {st_mode=S_IFDIR|0700, st_size=0, ...}, AT_EMPTY_PATH) = 0
  getuid()                                = 1000
  openat(5, "files", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
  mkdirat(5, "files", 0700)               = 0
  openat(5, "files", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 6
  openat(5, "info", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
  mkdirat(5, "info", 0700)                = 0
  openat(5, "info", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 7
  close(5)                                = 0
  openat(7, "tst_qfile.moveToTrashOpenFile.fjYRxv.trashinfo", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0666) = 5
  openat(AT_FDCWD, "/usr/share/zoneinfo/UTC", O_RDONLY|O_CLOEXEC) = 8
  newfstatat(8, "", {st_mode=S_IFREG|0644, st_size=114, ...}, AT_EMPTY_PATH) = 0
  newfstatat(8, "", {st_mode=S_IFREG|0644, st_size=114, ...}, AT_EMPTY_PATH) = 0
  read(8, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 114
  lseek(8, -60, SEEK_CUR)                 = 54
  read(8, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 60
  close(8)                                = 0
  write(5, "[Trash Info]\nPath=/home/tjmaciei"..., 103) = 103
  renameat(AT_FDCWD, "/home/tjmaciei/tst_qfile.moveToTrashOpenFile.fjYRxv", 6, "tst_qfile.moveToTrashOpenFile.fjYRxv") = 0
  close(5)                                = 0
  close(6)                                = 0
  close(7)                                = 0

On subsequent runs:

  openat(AT_FDCWD, "/home/tjmaciei/.qttest/share/Trash", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 5
  newfstatat(5, "", {st_mode=S_IFDIR|0700, st_size=18, ...}, AT_EMPTY_PATH) = 0
  getuid()                                = 1000
  openat(5, "files", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 6
  openat(5, "info", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = 7
  close(5)                                = 0
  openat(7, "tst_qfile.moveToTrashOpenFile.sPjrcA.trashinfo", O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC, 0666) = 5
  openat(AT_FDCWD, "/usr/share/zoneinfo/UTC", O_RDONLY|O_CLOEXEC) = 8
  newfstatat(8, "", {st_mode=S_IFREG|0644, st_size=114, ...}, AT_EMPTY_PATH) = 0
  newfstatat(8, "", {st_mode=S_IFREG|0644, st_size=114, ...}, AT_EMPTY_PATH) = 0
  read(8, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 114
  lseek(8, -60, SEEK_CUR)                 = 54
  read(8, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 60
  close(8)                                = 0
  write(5, "[Trash Info]\nPath=/home/tjmaciei"..., 103) = 103
  renameat(AT_FDCWD, "/home/tjmaciei/tst_qfile.moveToTrashOpenFile.sPjrcA", 6, "tst_qfile.moveToTrashOpenFile.sPjrcA") = 0
  close(5)                                = 0
  close(6)                                = 0
  close(7)                                = 0

Change-Id: I9d43e5b91eb142d6945cfffd1787117927650dab
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2023-10-17 19:08:25 -07:00
Thiago Macieira
77c661b275 moveToTrash/Unix: use lower-level API to write the info file
So we can more easily get any errors from attempting to write the file.
It is possible to get them with QFile, by either doing .flush() or using
QIODevice::Unbuffered, but using the C API is a definite sure way. Plus,
since this is QFileSystemEngine, this avoids the possibility that QFile
may choose to use a different file engine than the native one, for some
reason. And it reduces overhead.

This allows us to more easily detect why the file creation failed and
therefore stop looping if the error wasn't EEXIST. That will avoid an
infinite loop in case the necessary directories exist but aren't
writable.

It's also moved above the renaming, such that the failure to populate
the info file prevents the renaming too. Both operations can have the
same likely errors, ENOSPC and EIO. The likelihood of EIO is very low,
for both; but for ENOSPC it's far more likely for writing the
file. Avoiding the ENOSPC error for the renaming is handled in a later
commit.

Change-Id: I9d43e5b91eb142d6945cfffd1786d417142ac728
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2023-10-17 19:08:25 -07:00
Tor Arne Vestbø
7152a1d0be Add missing static to constexpr in keyevents test
Change-Id: I9e83876aadca3254042eb48ed51287e403830cf0
Reviewed-by: Liang Qi <liang.qi@qt.io>
2023-10-17 23:34:22 +02:00
Mate Barany
0345f07dd1 Support body for an HTTP GET request
Add two overloads to QNetworkAccessManager to support GET requests
with body.

Modify QNetworkReplyHttpImpl as well as these requests should not
be cached.

If the request is redirected it is possible that its type changes
from POST/PUT to GET and in this case the message body is deleted.
However, if a GET request has a body it should keep it after it has
been redirected - modify QNetworkReplyHttpImpl to keep the message
body after it has been redirected.

Fixes: QTBUG-112871
Change-Id: Ib01898638ed94238a98291870a5c51d56030868a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2023-10-17 21:23:42 +02:00
Milla Pohjanheimo
5ceb78e8d9 Add binary compatibility file for 6.6.0
Task-number: QTBUG-117583
Pick-to: 6.6
Change-Id: I9b63b916a59ddaeb89d2b819b36ee9dc57851dac
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2023-10-17 22:23:42 +03:00
Mårten Nordheim
3e6b42ae9d compressEvents: limit iteration
Slightly improves performance in the new benchmark

Change-Id: I2d71143ff7bc1f32ebb172f20be1843dec123e6c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-10-17 21:23:41 +02:00
Mitch Curtis
ec5383efc3 selftests: document how to run subtests from Windows' cmd.exe
It deoesn't like single quotes, which must be replaced with doubled-up
double quotes.

Pick-to: 6.2 6.5 6.6
Change-Id: I8e5f8047e72e4433926a9f4f2044407a4d823682
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-17 12:26:07 +08:00
Mårten Nordheim
13c4e11c49 http2: When a reply is removed from the queue, only remove one
We were using the .remove(Key) API on the map instead of
erase(iterator), so we were removing any reply of the same priority that
had not yet been popped from the queues.

Rewrote to drop loop and only work with iterators.
This issue was there since SPDY days, so not picking all the way back to
5.15, where HTTP2 anyway is not enabled by default.

As a drive-by, drop the #ifndef QT_NO_SSL, which was also there from
SPDY times, which was TLS-only.

Pick-to: 6.6 6.5 6.2
Fixes: QTBUG-116167
Change-Id: Id7e1eb311e009b86054c1fe3d049c760d711a18a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-10-16 19:28:26 +02:00
Volker Hilsheimer
80d4d55e25 JNI: add QJniArray class for easier working with arrays
Implements an iterator API and other standard member access functions
for sequential containers so that we can use ranged-for over an object
that is a jarray. Provides read-only access to individual elements
(which is mostly relevant for arrays of objects), or the entire data()
as a contiguous memory block (which is useful for arrays of primitive
types).

QJniObject call functions can return QJniArray<T> when the return type
is either explicitly QJniArray<T> or T[], or their Qt equivalent (e.g.
a jbyteArray can be taken or returned as a QByteArray). If the return
type is a jarray type, then a QJniObject is returned as before.

Arrays can be created from a Qt container through a constructor or the
generic fromData named constructor in the QJniArrayBase class, which
implements the generic logic.

Not documented as public API yet.

Added a compile-time test to verify that types are mapped correctly.
The function test coverage is added to the QJniObject auto-test, as
that already provides the Java test class with functions taking and
returning arrays of different types.

Change-Id: I0750fc4f4cce7314df3b10e122eafbcfd68297b6
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-16 18:43:16 +02:00
Mitch Curtis
3f2b54f0a1 selftests: respect ASAN_OPTIONS
Ensure that this environment variable is respected, as ASAN errors
(e.g. memory leaks) can cause the selftests to fail since they expect
no errors in their output.

Fix an incorrect function name in a comment, while we're at it.

Fixes: QTBUG-118041
Pick-to: 6.5 6.6
Change-Id: I07502101aabd8743df898ae8fe4a693c4733c4af
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-10-16 12:37:08 +08:00
Thiago Macieira
b470da9107 tst_QStorageInfo: align the columns without newlines
Change-Id: I9d43e5b91eb142d6945cfffd17874a50565a97d6
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-15 18:37:07 -07:00
Thiago Macieira
b0329f8560 tst_QFile::moveToTrash: add tests for /var/tmp
These must pass, but they're highly unlikely to be trashable because
/var/tmp is usually not its own filesystem (it might be a subvolume of
its own, but usually isn't). Instead, it's usually part of / or /var.

On my machine:
 openat(AT_FDCWD, "/var/.Trash", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
 openat(AT_FDCWD, "/var/.Trash-1000", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
 mkdirat(AT_FDCWD, "/var/.Trash-1000", 0700) = -1 EACCES (Permission denied)

Change-Id: Ifeb6206a9fa04424964bfffd17884246a4d27443
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-15 18:36:50 -07:00
Thiago Macieira
a40341366f tst_QFile::moveToTrash: use QDir::tempPath() for the rows w/ "temporary"
Both QTemporaryFile and QTemporaryDir are documented to use the current
directory if given a pattern. That can be anything & arbitrary, so it
doesn't give us consistency in checking. Moreover, it might be a read-
only directory.

Drive-by fix the number of 'X'.

Task-number: QTBUG-117449
Pick-to: 6.6
Change-Id: Ifeb6206a9fa04424964bfffd178841c44e9636a0
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2023-10-16 01:36:49 +00:00
Thiago Macieira
ef22527bf5 tst_QFile::moveToTrash: avoid QSKIP+FAIL condition
QtTest can't handle a test that does both. This ends up recorded as a
skip in the summary.

Pick-to: 6.6
Change-Id: Ifeb6206a9fa04424964bfffd1788412a438085b0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-10-15 18:36:48 -07:00
Pavel Dubsky
3373247873 Introduce QComObject base class
This base class implementation for COM objects provides IUnknown
interface implementation with reference counting which will allow to
keep all this functionality and implementation in the same place.

Pick-to 6.6 6.5

Change-Id: I8ec597b1040ac33295317e06338ffdcb61b78f85
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-13 21:29:48 +02:00
Mårten Nordheim
7fd0397c66 tst_http2: Use QCOMPARE for the nRequests check
Makes it easier to get an idea of what went wrong

Change-Id: Idace20ecf008fa906780881b62ed44ac36751123
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-10-13 19:57:29 +02:00
Marc Mutz
368ea559eb QSpan: add C++23 c{,r}{begin,end}()
It was weird that they were missing. Now that C++23 added them to
std::span, add them to QSpan, too.

Pick-to: 6.6
Change-Id: I4a9b1fdeda66bc7b133c8f7b3b269656e5faffa3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-12 21:38:54 +02:00
Marc Mutz
4a7c76d4a5 Include what you need: <QPointer>
All these TUs relied on transitive includes of qpointer.h, maybe to a
large extent via qevent.h, though, given that qevent.h is more or less
the only public QtBase header that includes qpointer.h, something else
seems to be at play here.

Said qevent.h actually needs QPointer in-name-only, so a forward
declaration would suffice. Prepare for qevent.h dropping the include.

The algorithm I used was:

If the TU mentions 'passiveGrabbers', the name of the QEvent function
that returns QPointers, and the TU doesn't have qpointer.h included
explicitly, include it. That may produce False Positives, but better
safe than sorry. Otherwise, in src/, add an include to all source and
header files which mention QPointer. Exception: if foo.h of a foo.cpp
already includes it, don't include again.

Task-number: QTBUG-117670
Change-Id: I3321cccdb41ce0ba6d8a709cea92427aba398254
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-10-12 21:38:54 +02:00
Assam Boudjelthia
3b6d288e3b Android: Simplify Qt for Android hierarchy, less Java reflection!
This changes takes Qt for Android Java code away from the Delegate
classes that uses heavily Java reflection to invoke Activity/Service
calls and overrides. So instead of that, now, we have a QtActivityBase
and a QtServiceBase classes which handle the override logic needed for
Qt directly without reflection.

These Base classes extend Android's Activity and Service directly, and
are inside the internal Qt android package (under Qt6Android.jar).

For example, to handle onConfigurationChanged, instead of the current
way where we need this in QtActivityDelegate:

 public void onConfigurationChanged(Configuration configuration)
 {
     try {
         m_super_onConfigurationChanged.invoke(m_activity, configuration);
     } catch (Exception e) {
         e.printStackTrace();
     }
         handleUiModeChange(configuration.uiMode &
Configuration.UI_MODE_NIGHT_MASK);
 }

And then this in QtActivity:

 @Override
 public void onConfigurationChanged(Configuration newConfig)
     {
         if (!QtLoader.invokeDelegate(newConfig).invoked)
             super.onConfigurationChanged(newConfig);
    }
    public void super_onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
    }

And having to keep it's Method handles around and then use Java
reflection
to call the override behavior done by Qt and the superclass methods.

instead of that, we can do it now in QtActivityBase like:

 @Override
 public void onConfigurationChanged(Configuration newConfig)
 {
     super.onConfigurationChanged(newConfig);
     handleUiModeChange(newConfig.uiMode &
Configuration.UI_MODE_NIGHT_MASK);
 }

Then, we would still have our user facing QtActivity class which extends
QtActivityBase and benefit from the same implementation of Qt logic done
in the base class.

An additional benefit to this approach is that now QtActivity will be
very lightweight and doesn't need to have all the boilerplate code as
before.

[ChangeLog][Android] Simplify Qt for Android public bindings
(QActivity, QtService and QtApplication) by implementing base
classes which use the delegate implementions directly and avoid
reflection.

Task-number: QTBUG-115014
Task-number: QTBUG-114593
Change-Id: Ie1eca74f989627be4468786a27e30b16209fc521
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-10-12 19:16:47 +03:00
Ahmad Samir
042c38379f tst_Gestures: compile with QT_NO_FOREACH [2/2]
The loops are iterating over local const containers, so use ranged-for.

Remove '#undef QT_NO_FOREACH'.

Task-number: QTBUG-115839
Change-Id: I252f048e3c469bf9bb34cb0756ccbd57571fd886
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-11 23:06:20 +03:00
Ahmad Samir
e48e2b3b4a tst_Gestures: compile with QT_NO_FOREACH [1/2]
GestureWidget::ignoredGestures QSet:
- elements are inserted in the container in a top-level test function,
  then a CustomEvent is constructed and sendCustomGesture() is called,
  which sends the events, invoking the GestureWidget::event() overload,
  the latter iterates over the container, thus the container isn't
  changed while it's being iterated over, because the code can't recurse
  into the top-level test function and that's where the container is
  modified later on (by inserting or by calling widget.reset() which
  clears the container)
- the loop body doesn't change the container

So use ranged-for and std::as_const.

The same logic applies to the GestureItem::ignoredGestures QSet.

Task-number: QTBUG-115839
Change-Id: Icf95e90a8af5aa7e947035704121557494afc326
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-11 23:06:20 +03:00
Edward Welbourne
29af4b1833 Sort out an anomaly in tst_QDateTime::springForward()
It noted that an unspecified function claimed the offset it was
checking should be +1, while testing it against that or -1. The
function turns out to be QDateTime::addDays(), whose doc did indeed,
misleadingly, say that it lands after a gap it would have hit. It in
fact overshoots the gap in the direction of its change. Amend its
docs, likewise those of addMonths() and addYears(), to reflect the
true behavior.

Amend the test to look at the direction of the step its taking and
anticipate that the adjustment will be in the same direction; then
compare the actual adjustment to that.

Change-Id: I9ab918fac0ab2195ef014983f37fccc435bf0498
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-10-11 22:06:20 +02:00
Edward Welbourne
c23d00078c Let QDateTime::offsetFromUtc() work for invalid date-times
The implementation previously worked for non-short date-times, where
the offset has been remembered since construction. This included the
case of zoned times (and local times more than 2^55 msec away from the
start of 1970) that hit a spring-forward's gap; but excluded local
times that did the same (within 2^55 msec of the epoch).

This precluded an offset check in a spring-forward test, now added.

We can in fact determine the offset whenever we got a valid date and
time (we do so in the course of initializing the object, and when
asked for toMSecsSinceEpoch(), even when invalid), and we should not
use the value of the recorded offset if we didn't get a valid date and
time, so amend to always return 0 if we didn't get valid date and time
and always report the correct offset otherwise.

In the process, amend offsetFromUtc()'s computation to directly
resolve the date-time, rather than doing so via toMSecsSinceEpoch(),
which has to repeat decision-making offsetFromUtc() has already done
by the time it calls it. Also amend toMSecsSinceEpoch() to return 0 if
we didn't have a valid date and time to begin with, so it only
attempts to produce a useful result in the case where construction
attempted to resolve the date-time.

Change-Id: I6574e362275ccc4fbd8de6f0fa875d2e50f3bffe
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-11 22:06:19 +02:00
Edward Welbourne
4aba97e062 Adjust msecs instead of offset for spring-forward resolution times
The resolution selects a point in time outside the gap, which will be
represented by toMSecsSinceEpoch()'s return, despite the QDT object's
isValid() returning false. Previously we retained the
originally-calculated msecs, so as to keep date() and time() matching
what was asked for. However, this required adjusting offset, which was
not remembered for local times within 2^55 milliseconds of the start
of 1970. This lead to an inconsistency between the offset from UTC
reported for the resolution for a local time further from the epoch,
or for a time-zone, and the actual offset from UTC at the time
indicated by the return from toMSecsSinceEpoch().

Instead, retain the actually calculated offset (even if we aren't
going to remember it) and adjust the msecs to the value that ensures
toMSecsSinceEpoch() will get the selected resolution. This
incidentally means that, when toMSecsSinceEpoch() has to re-resolve
(for a local time within 2^55 msecs of the epoch), it avoids
revisiting the complications of hitting the gap.

In passing, change internal stateAtMillis() to take the QTimeZone it
is passed by const reference, to save a copy (noticed during debug).
Also tweak a comment in a test to be explicit about a default value.

[ChangeLog][QtCore][Possibly Significant Behavior Change] When
QDateTime is instantiated for a combination of date and time that was
skipped, by local time or a time-zone, for example during a
spring-forward DST transition, the invalid result's time() - and, in
rare cases, date() - no longer match what was asked for. Instead,
these values and offsetFromUtc() now match the point in time
identified by toMSecsSinceEpoch().

Change-Id: Id61c4274b365750f56442a4a598be5c14cfca689
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-10-11 22:06:19 +02:00
Tor Arne Vestbø
cd4000a97d Use QtGui to match QWindow based shortcuts, even when QApplication is used
If a QShortcut is registered with a QWindow as its parent, but QApplication
is used, we end up in QApplicationPrivate::createShortcutPrivate(), and
create a QtWidgetsShortcutPrivate that implements shortcut context matching
via qWidgetShortcutContextMatcher.

The problem is that qWidgetShortcutContextMatcher expects the windows
to be QWidgetWindows, which meant that plain QWindow based shortcuts
would always fail.

This can happen for example if a QApplication is used in Qt Quick
to provide dialog fallbacks, but QShortcuts are otherwise used
with plain QWindows, or QQuickWindows e.g.

We now defer the check of whether there's an active (widget) window,
and fall back to QtGui's simpleContextMatcher in case we don't find
a QWidget, QAction, or QGraphicsWidget shortcut owner to handle
the matching for.

Note: We don't support shortcut matching for QAction in QtGui,
but this is left for another day. There is also a discrepancy
between how QtGui and QtWidgets handles Qt::ApplicationShortcut.
The former will treat it as a match even if there is no active
QWindow, while the latter requires that there's an active widget
window.

Fixes: QTBUG-116221
Change-Id: I487995f2e660a40f6556828b84a521d81a58f1b6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-11 20:32:05 +02:00
Tor Arne Vestbø
260ac1891a tst_QInputMethod: Don't assume test is the only one calling functions
After d9bb8c0a17 we call inputDirection()
on the platform input context to initialize the direction at startup.

The test can't assume there are no other callers to the functions
in the QPlatformInputContext layer.

Change-Id: Ic1cecd608b2759e703a17838fcf24b4ff53ad07e
Reviewed-by: Liang Qi <liang.qi@qt.io>
2023-10-10 19:29:27 +02:00
Shawn Rutledge
8e0bf6e05b Make tests/manual/qtabletevent/device_information build standalone
It's very hard to test on Android otherwise: Creator isn't cooperating
well enough with Android Studio / SDK manager with where stuff is
installed, qmake doesn't build an apk, and qt-cmake-standalone-test
doesn't work wth Android either.

Renamed the executable to tablet_device_info so it's a bit less
confusing on device launcher UIs.

Task-number: QTBUG-86297
Change-Id: I3bb7f816e43f8df4183be1c0866e228befa9e8d9
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
2023-10-10 18:27:22 +02:00
Anton Kudryavtsev
ebf1538fa6 Qt::mightBeRichText: port to QAnyStringView
[ChangeLog][QtGui] Ported Qt::mightBeRichText() to QAnyStringView
(was: QString).

Change-Id: Ib5633ed45cba5f4f1211438397624574f7431908
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-10-09 22:19:24 +00:00
Mårten Nordheim
0fa4af060e QTemporaryFile: Add support for std::filesystem::path
Since it hides QFile's overloads this was not supported for
QTemporaryFile.

[ChangeLog][QtCore][QTemporaryFile] Added support for passing
std::filesystem::path to rename and createNativeFile.

Change-Id: I909ff1d5b9c586824c9901d7dad278dfad09ffc3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-09 16:25:57 +02:00
Tor Arne Vestbø
ab99cf6077 QKeySequence::toString(): Treat Modifier+Qt::Key_Unknown as empty string
We were already doing this for a key combination without modifiers,
but now we do the same for e.g. Control+Unknown. This matches the
behavior we have for QKeySequencePrivate::decodeString(), where
we return Qt::Key_Unknown if we can't resolve the key, even if
we have resolved some valid modifiers, e.g. "Meta+Trolls" as in
the tst_QKeySequence::parseString() test.

Change-Id: I238e29276e6ce356ae60c67585739587fa388f07
Reviewed-by: Liang Qi <liang.qi@qt.io>
2023-10-09 15:25:54 +02:00
Thiago Macieira
1033780b3c tst_QFile: extend moveToTrash tests to exercise more corner cases
Added moveToTrashDuplicateName() to see what happens if you attempt to
trash two files with the same exact full path. Both files should get
independently moved to the trash bin and not clobber each other.

Added moveToTrashXdgSafety() to test that QFileSystemEngine will
properly skip over an unsafe $root/.Trash directory, as required by the
XDG specification. I think the specification should also make security
requirements on $root/.Trash-$uid too, but that's for another change.

Pick-to: 6.6
Change-Id: I9d43e5b91eb142d6945cfffd1786cd60e4244c7c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-06 18:43:29 -07:00
Ahmad Samir
032ffb70a8 QAbstractSocketEngine: port to QDeadlineTimer
qnativesocketengine_win.cpp: don't check if timeout is < 0, because
remainingTimeAsDuration() doesn't return negative values.

All the changes done in one go, not function by function, as that causes
the least churn. You can think of them as a couple of very similar
changes repeated various times.

Drive-by change: replace `forever {` with `for (;;)`

Task-number: QTBUG-113518
Change-Id: Ie9f20031bf0d4ff19e5b2da5034822ba61f9cbc3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-07 02:28:12 +03:00
Axel Spoerl
92d837e684 QDockWidget: Do not propagate title from a closed dock widget
When a dock widget is closed while floating, it still reports being
floating even though the QWidget::windowHandle()->isVisible() returns
false. This is documented behavior and will not be changed.

c153066baa relied on the isFloating() to
return false, if the dock widget is closed. When the window title was
changed by setWindowTitle(), the change was overridden by reading the
old value from the window handle.

=> Amend the patch and add a windowHandle()->isVisible() as a condition.

In c153066baa, an autotest for the title
propagation (QTBUG-113591) was added to floatingTabs().

=> Harden the setWindowTitle() test function. Move the tests related to
QTBUG-113591 and QTBUG-117764 to this function.

Fixes: QTBUG-117764
Pick-to: 6.6 6.5
Change-Id: Id37a9a22d4d13abad4ea55c74ea4e834bdb2bfab
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2023-10-07 00:01:22 +02:00
Mårten Nordheim
0c4b2779ff tst_http2::redirect: reduce length of test
By fixing how many requests we are expecting to _finish_.

Since the nRequests variable is only decreased once a
request is finished, we only actually expect 1. No matter
how many times it gets redirected.

This was the slowest test-function in the test, clocking in at
10 seconds. Now it's sub 500ms.

Pick-to: 6.6 6.5
Change-Id: I544360f0928466c1bc0fbc6806952ccec588d131
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-10-06 17:40:23 +00:00
Tor Arne Vestbø
5fce4ff2c2 keyevents test: Force left to right when outputting key combinations
Otherwise characters in right to left languages like Hebrew might
mess up the output.

Change-Id: I8753e7e672159ed515dc6152c3629adf91cfd4a9
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2023-10-06 15:48:46 +02:00
Marc Mutz
bc3ae300c5 tst_QStringApiSymmetry: add more invalid UTF-8 sequences
These represent US-ASCII characters incorrectly encoded as a two-octet
UTF-8 sequence.

Pick-to: 6.6 6.5
Change-Id: I5b1d58066d08cf61583dabcd71dd2f3ac7a3585a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-06 06:59:02 +02:00
Christian Ehrlicher
4e8b54eb81 Preparations to deprecate QItemDelegate
QItemDelegate was superseded since Qt4 by QStyledItemDelegate but it
took until Qt6.7 to remove the last occurrences in qtbase.
 - remove unused includes / replace with qabstractitemdelegate.h
 - replace references in the documentation with QStyledItemDelegate
 - adjust the examples and tests to use QStyledItemDelegate

Pick-to: 6.5 6.6
Change-Id: I246755004ce2d01192a726ca0972106c237df0cc
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
2023-10-05 21:08:45 +02:00
Christian Ehrlicher
9ed25b413f Tests/QListView: fix internalDragDropMove test for openSUSE
On some xcb platforms the xcb_configure_notify_event_t is sent after the
window is fully exposed which leads to a wrong position for
QWidget::mapToGlobal() which makes the test fail.
Fix it by waiting for a move event with a position != 0,0 before
starting the drag'n'drop operation.

Fixes: QTBUG-94250
Change-Id: If91a15815205ba9dcea36248d9de03ed0a7e5822
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-10-05 19:08:45 +00:00
Anton Kudryavtsev
9187348505 qtextdocument::insertText: port to QSV
and add QChar overload to reduce allocations
Also port tests from char* literals to char16_t literals

Change-Id: I99381a2da08d9d35e6135c48bd92bd8d72533065
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-05 22:08:45 +03:00
Marc Mutz
1219dbcd12 QPointer: ensure construction from nullptr is constinit'able
Construction from nullptr wasn't, before, because it was using the
QPointer(T*) constructor, which cannot be constexpr. Add a constexpr
QPointer(std::nullptr_t) constructor to enable this use-case.

This requires to mark the (T*) constructor as Q_WEAK_OVERLOAD,
otherwise legacy construction from a literal 0 would be ambiguous.

No documentation changes needed, as the set of valid expressions
(apart from constinit'ing) has not changed. Mention the nullptr ctor,
though, without \since.

Add a test to confirm that contruction from derived still works.

Change-Id: If9d5281f6eca0c408a69f03fecba64a70a0c9cf0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-05 20:19:40 +02:00
Volker Hilsheimer
fd4319700f JNI: Silence and harden QJniEnvironment test
Ignore expected warning messages when looking up classes, methods, or
field that don't exist. Make the test implicitly fail for any other
warning messages.

Change-Id: I79ec799102b1ab9424aa39c5255413931b8ad152
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-10-05 19:50:33 +02:00
Hatem ElKharashy
888016a53f Fix compilation error for QRhi stereo manual test
Add a guard to prevent compilation error on
non-Windows platform

Change-Id: Ibe0d74c1dfe3d4656addeb80c702b6e254d37d84
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Kristoffer Skau <kristoffer.skau@qt.io>
2023-10-05 08:18:01 +00:00
Thiago Macieira
3a49d7d4e5 tst_QFile: extend virtualFile() to find QtCore and QtTest
In non-static builds, of course.

Change-Id: Ifbf974a4d10745b099b1fffd1777ac97c0921759
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-10-04 12:04:45 -07:00
Rym Bouabid
b956fec7ee Remove Custom Type Example and Custom Type Sending Example
The whole Q_DECLARE_METATYPE part is superfluous in these two examples,
as QVariant works with any type as long as it is copy-constructible.
And QVariant will call the equivalent of qRegisterMetaType, so that
doesn't need to happen, either.
Showing how to integrate the type with qDebug is fine in theory, but
also a repetition of content that can be found in other places.

Given that there isn't much else being shown in these two examples, it's
better to remove them from examples and move them to manual tests.

Some parts of "Custom Type Example" were used as snippets in other
documentations under qtbase/src/corelib. So, they were added in
customtypeexample.cpp file in the snippets folder.

Fixes: QTBUG-117001
Pick-to: 6.6 6.5
Change-Id: I45b16338912e3f7394cbb5169642bd31af32d5e1
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-10-04 21:04:45 +02:00
Tor Arne Vestbø
c8599f1626 Add QShortcut test for Qt::ApplicationShortcut
A Qt::ApplicationShortcut shortcut is not tied to a specific window.

We do however document that the shortcut "is active when one of the
applications windows are active", which seems like a strange limitation,
but for now we honor it in our test as well by making another window
active.

Change-Id: I235230ff69df29ee43d356d3efaeedb20071faf3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-10-04 20:36:53 +02:00
Marc Mutz
8b66184625 tst_QPointer: ensure default-constructed objects are constinit'able
Construction from nullptr isn't, because it's using the QPointer(T*)
constructor, which cannot be constexpr.

Pick-to: 6.6 6.5
Change-Id: I19129a0fca5873e83d20351a909a7994399bfcce
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-04 07:44:04 +02:00
Marc Mutz
1cf0f8e7c3 tst_QPointer: add checks for CTAD
No pathological findings :)

Pick-to: 6.6 6.5 6.2
Change-Id: Ifbbca223a5e612e7abb67c0364d4354a9d8174e3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-04 07:44:01 +02:00
Christian Ehrlicher
cb4e7f4176 QHeaderView: add test for rows/columns moved
Add a testcase to make sure the signals for moveing rows are properly
connected from the model to the corresponding QHeaderView slots.

Task-number: QTBUG-117698
Pick-to: 6.6 6.5
Change-Id: I354f8836d3de58a8bf51da7a8c0859a673ec9339
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-10-03 18:49:43 +00:00
Eskil Abrahamsen Blomfeldt
a890df0283 coretext: Support variable application fonts
Named instances of variable application fonts are exposed
automatically through CTFontManagerCreateFontDescriptorsFromData()
(and also for the URL equivalent).

The main change here is just to call this instead of the overload
which only returns the first font.

Note that this also updates the test: This is because the conversion
from CoreText normalized weight values to TTF values is not 100%.
In the CoreText code, we map Heavy (0.56) to ExtraBold, but ExtraBold
gets converted to 0.6, which is closer to the CoreText value for Black
(0.62).

To avoid hitting this inconsistency, the QtExtraBold has been changed
to Black weight instead, which resolves to the same on all platforms.

Task-number: QTBUG-108624
Change-Id: Ied6d42e9e3e1ba8b7102936c5be3d285b3d9e07f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-10-03 19:25:46 +02:00
Tor Arne Vestbø
8606f33641 Simplify tst_QShortcut
There's no need for the manual sendKeyEvent, as QTest already
has the ability to send synthetic clicks, and we don't need
a colored window to test shortcut activation.

Pick-to: 6.6
Change-Id: I8409888664e2316bec4ea64f21dbb8b6915091f4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-10-02 22:53:11 +02:00
Ahmad Samir
76afc35328 QStringList: refactor a unittest
- Initialize QStringList with an initializer_list instead of old style
  operator <<()
- Use Qt::StringLiterals more, better readability
- Test CaseSensitivity

Change-Id: If7dde14333d54b8c2f682036634ad94d5f9f9c74
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-10-02 22:12:35 +03:00
Eskil Abrahamsen Blomfeldt
500be123f4 Support variable applications fonts with DirectWrite
For GDI, there doesn't seem to be any way to do this, so it depends
on selecting the DirectWrite font database explicitly.

This moves the supportsVariableApplicationFonts() check into the
QPlatformFontDatabase instead of the font engine, since that's
where it belongs.

[ChangeLog][Fonts] Added support for selecting named instances in
variable application fonts when using the DirectWrite backend.

Task-number: QTBUG-108624
Change-Id: I51e0fedd7a9616088a06453a1d17f48bd18fa5a7
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-10-02 18:00:33 +02:00
Christian Ehrlicher
2203dec57b Tests/QAbstractiItemView: fix runtime warnings
Fix runtime warnings about testdata with the same name.

Pick-to: 6.6 6.5
Change-Id: I5d4927cc53be3e08a524498db42a8a08396ced8e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-10-01 15:44:01 +02:00
Volker Hilsheimer
9b37762c55 JNI: Add promotion for signed char and extend test case
The jbyte type is a signed char, which also promotes to int in variadic
argument functions.

Extend the test case to make sure that we don't get any warnings for
the most relevant parameter types.

Change-Id: I7811e1eebdbc989ab5989eb1a2c502acd0540bc7
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
2023-09-29 16:50:41 +02:00
Michael Weghorn
5093e517b9 a11y: Keep current combobox entry in sync
When changing the selected index in a combo box,
also update the current index in the item view's
selection model right away, and don't delay this
until when the combobox popup gets shown in
QComboBox::showPopup.

This is needed to make sure that the selection
is properly exposed to the accessibility layer.

On the accessibility layer, QAccessibleComboBox,
the a11y implementation for the combobox, exposes
the entries in its list child
(s. QAccessibleComboBox::child) and Orca queries
the selected item when the combobox gets focus,
which didn't return the proper results earlier,
resulting in no or the wrong entry getting
announced.

Extend the existing combobox a11y tests
accordingly.

Pick-to: 6.6 6.5
Fixes: QTBUG-117644
Change-Id: Ia26de5eafd229f7686745a2fbe03fc1eb6a713f8
Reviewed-by: Liang Qi <liang.qi@qt.io>
2023-09-29 09:55:40 +00:00
Dennis Oberst
016addc201 QString: assign() [4/4]: (it,it) overload for UTF-8 data types
Implement the missing overload to handle UTF-8 specific data types,
including char8_t (C++20), char, uchar and signed char.

Introduce the helper function 'assign_helper_char8' which handles the
non-contiguous_iterator case. The contiguous_iterator case is already
handled by the QAnyStringView overload.

Include 'qstringconverter.h' at the end of the file, since it can't
be included at the top due to diamond dependency conflicts.
QStringDecoder is an implementation detail we don't want users to
depend on when using assign(it, it). It would be unnatural to not
be able to use a function just because we didn't include an
apparently unrelated header.

[ChangeLog][QtCore][QString] Enabled assign() for UTF-8 data types.

Fixes: QTBUG-114208
Change-Id: Ia39bbb70ca105a6bbf1a131b2533f29a919ff66d
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-09-28 17:58:41 +00:00
Po-Hao Su
7c4aa794ca SQLite: Handle identifiers correctly
This change can be described in the following 2 categories:
1. Support 3 ways to escape identifiers mentioned in SQLite Keywords
   In SQLite Keywords (https://sqlite.org/lang_keywords.html), it shows
   that there are 3 ways to escape identifiers, i.e., "", [], ``. So, I
   have overridden "bool isIdentifierEscaped(const QString &,
   IdentifierType)" to support it. In addition, there was a bug of
   _q_escapeIdentifier. If there is a field name called length [cm],
   which uses square brackets to show units, _q_escapeIdentifier will
   not escape it to "length [cm]".
2. Identify identifiers correctly if identifiers have been escaped
   There is a bug of QSQLiteDriver::record and
   QSQLiteDriver::primaryIndex.
   If we input escaped identifiers with separator, let's say
   "databaseName"."tableName", both will change the input into
   databaseName"."tableName, which is incorrect and causes
   qGetTableInfo cannot get the right results. In addition, I overrode
   stripDelimiters to strip "databaseName"."tableName" correctly.

There are still some assumptions for isIdentifierEscaped,
escapeIdentifier, and stripDelimiters, but I think this change it better
than what we have now.
1. For isIdentifierEscaped, if identifiers have a dot and the dot is a
   separator, it is the users' responsibility to escape the pair of
   schema and table name correctly. For example,
   "aSchemaName"."aTableName", not "aSchemaName".a"TableName". That's
   because we don't know whether the dot is just a dot of the name or a
   separator.
2. For escapeIdentifier, if identifiers have a dot and the parts before
   and after the dot are not escaped, escapeIdentifier will treat the
   dot as part of the table name or field name. The same as the item
   above, it is users' responsibility to do it right.
3. For stripDelimiters, the same as above, it is users' responsibility
   to do escape if users want to use format schemaName.tableName or
   tableName.fieldName.

Change-Id: I9d036a2a96180f8542436188f75a220a0fe58257
Reviewed-by: Po-Hao Su <supohaosu@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2023-09-28 20:51:33 +08:00
Giuseppe D'Angelo
a1bdee4697 is_virtual_base_of: suppress warnings in the test
We want to test the traits even on nonsensical types.

Change-Id: I63ed022c9529d9de9d336157e6f025937321ca16
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-09-28 09:40:23 +02:00
Volker Hilsheimer
185c3b080c JNI: Fix native functions that take a declared QtJniTypes class
Now that QtJniTypes::Objects are no longer primitive types that are the
same as a jobject, using those types in registered native functions
breaks. JNI will call those function with a jobject on the function
pointer, and lacking any type safety, the call to the registered
function will proceed with a wrong type of object on the stack.

To fix that, register the native function via a proxy that is a variadic
argument function, and unpack the variadic arguments into a list of
typed arguments, using the types we know the user-code function wants.
Then call the function with a tuple of those types using std::apply,
which gives us type safety and implicit conversion for free.

Add a test that exercises this.

Change-Id: I9f980e55d3d13f8fc16c410dc0d17dbdc200cb47
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2023-09-27 19:44:58 +02:00
Volker Hilsheimer
62cb5589b3 JNI: Make declared QtJniTypes classes proper QJniObjects
Instead of having a type that doesn't behave like a QJniObject, which
includes not holding a proper reference on the Java object, make the
QtJniTypes::Object type a QJniObject subclass that can be specialized
via CRTP to provide type-specific constructor and static functions.

QJniObject doesn't have a virtual destructor, but we subclass it only to
add a typed interface, without adding any additional data members.
Add versions of the static functions from QJniObjects to the
QtJniTypes::Object so that they can be called without explicitly
specifying the type or class name. This includes a constructor and named
constructors.

Constructing such objects means constructing a Java object of the class
the object type represents, as per the Q_DECLARE_JNI_CLASS declaration.
This is not without ambiguity, as constructing a type with a jobject
parameter can mean that a type wrapping an existing jobject should be
created, or that a Java object should be created with the provided
jobject as the parameter to the constructor (e.g. a copy constructor).
This ambiguity is for now inevitable; we need to be able to implicitly
convert jobject to such types. However, named constructors are provided
so that client code can avoid the ambiguity.

To prevent unnecessary default constructed QJniObjects that are then
replaced immediately with a properly constructed object, add a protected
QJniObject constructor that creates an uninitialized object (e.g. with
the d-pointer being nullptr), which we can then assign the constructed
jobject to using the available assignment operator. Add the special
copy and move constructor and assignment operators as explicit members
for clarity, even though the can all be defaulted.

Such QJniObject subclasses can then be transparently passed as arguments
into JNI call functions that expect a jobject representation, with the
QtJniTypes::Traits specialization from the type declaration providing the
correct signature.

QJniObject's API includes a lot of legacy overloads: with variadic
arguments, a explicit signature string, and jclass/jmethodID parameters
that are completely unused within Qt itself. In addition the explicit
"Object" member functions to explicitly call the version that returns a
jobject (and then a QJniObject). All this call-side complexity is taken
care of by the compile-time signature generation, implicit class type,
and template argument deduction. Overloads taking a jclass or jmethod
are not used anywhere in Qt, which is perhaps an indicator that they,
while nice to have, are too hard to use even for ourselves.

For the modern QtJniTypes class instantiations, remove all the overhead
and reduce the API to the small set of functions that are used all over
the place, and that don't require an explicit signature, or class/method
lookup.

This is a source incompatible change, as now QJniTypes::Object is no
longer a primitive type, and no longer binary equivalent to jobject.
However, this is acceptable as the API has so far been undocumented,
and is only used internally in Qt (and changes to adapt are largely
already merged).

Change-Id: I6d14c09c8165652095f30511f04dc17217245bf5
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2023-09-27 19:44:58 +02:00
Volker Hilsheimer
064b46779c JNI: Implement QJniObject::className to get the name of the class if not set
If we construct the QJniObject from a jobject, then we know the jclass,
but not the class's name. If className is called while the stored name
is empty, get the name of the jclass and updated the stored value.

Change-Id: Ic3332a6da2dac1eb6842f90da1b9264398a43155
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2023-09-27 19:44:58 +02:00
Tor Arne Vestbø
ca68fa01fe Add key events manual tests
Task-number: QTBUG-116873
Change-Id: I70c0199fa6244addf0f282aa8856935e3486270a
Reviewed-by: Alexis Murzeau <amubtdx@gmail.com>
Reviewed-by: Liang Qi <liang.qi@qt.io>
2023-09-27 17:47:19 +02:00
Ulf Hermann
c4bfd32cca QProperty: Steal currentCompatProperty while evaluating a different one
currentCompatProperty should point to the compat property that's
currently being evaluated. As soon as we start evaluating a new compat
property, it's invalid by definition. Temporarily disable it then.

Pick-to: 6.6 6.5 6.2
Fixes: QTBUG-109465
Change-Id: I7baba9350ebf488370a63a71f0f8dbd7516bf578
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-09-27 09:31:41 +00:00
Giuseppe D'Angelo
35878fa924 Long live qxp::is_virtual_base_of
To be used in QWeakPointer.

Change-Id: I5ee9dd0862a0b23d316aaadf5d68bef1ce609e8b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-26 22:32:51 +02:00
Volker Hilsheimer
218daa6f77 JNI: harden QJniObject test case
Fail the test when an unexpected warning message about a field, class,
or method not being found is generated from a JNI exception. Fix the
failure when trying to look-up a boolean field that is no longer
available, and ignore the one expected message from looking up an
unavailable class explicitly.

Change-Id: Ic5e4c003c64272f06a6d4da028e232abba75c4e4
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2023-09-26 19:58:25 +02:00
Volker Hilsheimer
f826d1615a JNI: Implicitly convert QString to jstring in API calls
Support this both for parameters and return types, in all template
functions for calling methods or accessing fields.

To manage the life-time of the temporary objects, create a local stack
frame in the JVM around the calling function. Popping that implicilty
releases all local refernces, so that we don't have to worry about
doing so explicilty. Adding a local reference to the temporary jstring
objects is then enough for the object to live as long as it's needed.

The LocalFrame RAII-like type needs a QJniEnvironment to push and pop
the frame in the JVM, so we don't need a local QJniEnvironment anymore.
Reduce code duplication a bit as a drive-by, and add test coverage.

Change-Id: I801a1b006eea5af02f57d8bb7cca089508dadd1d
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-09-26 19:58:25 +02:00
Volker Hilsheimer
281f499b20 JNI: remove compatibility alias for CTString
Add compile-time testing to make sure that we can declare a JNI
class String that maps to java/lang/String.

Change-Id: I2b68b2b46112e56b279f3fcddc3d71847a005924
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-09-26 19:58:25 +02:00
Wladimir Leuschner
cf6bccbcf5 Ensure stable sort in QListWidget
QlistWidgets with sorting enabled do not sort stable. A re-sort is
triggered when any Qt::ItemDataRole is changed and not only when
Qt::DisplayRole is changed. Due to an unstable optimization, the changed
element gets inserted at the beginning of their respective "equivalence
group".

This patch disables the optimization and ensures stable sorting
with std::stable_sort. Sorting is only performed, if the subset of
changed items in the range [begin, end] is not already sorted in the
whole list. For this purpose, it is assumed that the list has already been sorted before begin and after end. This assumption minimizes the subset to check.

Limits / side effect:
The patch focuses on the most common use case, which is a single item being changed. Replacing the optimization by std:stable_sort can potentially slow down the sorting performance of large data sets.

Task-number: QTBUG-113123
Pick-to: 6.5 6.6
Change-Id: Ib2bd08f21422eb7d6aeff7cdd6a91be7114ebcba
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
2023-09-26 16:45:11 +00:00
Giuseppe D'Angelo
89b6ad3ab5 QWeakPointer: fix the converting constructor from rvalues
When constructing a QWeakPointer<T> from a rvalue QWeakPointer<X>,
even if X* is convertible to T*, actually doing the conversion
requires access to the pointee's vtable in case of virtual inheritance.

For instance:

  class Base { virtual ~Base(); };
  class Derived : public virtual Base {};

Now given a `Derived *ptr`, then a conversion of `ptr` to `Base *` is
implicit (it's a public base), but the compiler needs to dereference
`ptr` to find out where the Base sub-object is.

This access to the pointee requires protection, because by the time we
attempt the cast the pointee may have already been destroyed, or it's
being destroyed by another thread. Do that by going through a shared
pointer. (This matches the existing code for the converting assignment.)

This requires changing the private assign() method, used by QPointer, to
avoid going through a converting move assignment/construction, because
one can't upgrade a QWeakPointer tracking a QObject to a QSharedPointer.
Given it's the caller's responsibility to guard the lifetime of the
pointee passed into assign(), I can simply build a QWeakPointer<T> and
use ordinary (i.e. non-converting) move assignment instead.

Change-Id: I7743b334d479de7cefa6999395a33df06814c8f1
Pick-to: 6.5 6.6
Fixes: QTBUG-117483
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-25 21:50:07 +02:00
Doris Verria
faae3dc6b1 QAbstractItemDelegate: Update spinbox editor value before committing
QAbstractItemView installs the delegate as an event filter on the
editor, so the delegate will get the focusOut event (and other
events) before the editor does. QAbstractItemDelegate will then
emit commitData, signaling that the "updated" data should be
written back to the model.
In the case where the editor of a delegate (QAbstractItemDelegate)
is a QSpinBox with keyboardTracking set to false, the value of
the spinbox won't be updated while typing, but only when the
spinbox's text edit focus is lost. In this case, the delegate's
commitData will be emitted before the spinbox has had a chance
to update the value in its handling of the focusOut event.
To fix, make sure to update the value before the data is
committed to the model in the delegate's tryFixup method.

Fixes: QTBUG-116926
Pick-to: 6.5 6.6
Change-Id: I68540964342407d23387e4404a0fe3f00d80eb5f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-09-25 15:12:05 +02:00
Volker Hilsheimer
6ca2008d6e QFile::moveToTrash: fix error reporting on Windows
If a move-to-trash operation failed, e.g. because the file was opened by
another process (or QFile), then the moveToTrash function would still
return true.

MSDN documents the IFileOperation::PerformOperations to return whether
the operation succeeded, but evidently this is only a statement about
the execution of queued up operations, not a statement about any of the
operations' success.

If the operation succeeded is reported by an HRESULT parameter
of the IFileOperationProgressSink::PostDeleteItem implementation,
and we ignored that parameter so far.

Check it via the SUCCEEDED macro, and set a boolean sink variable based
on that, which we can inspect to return the correct value.

Augment the test case by opening those files we create ourselves, and
if that fails (which it will on Windows, but not necessarily on other
platforms), then try again after closing the file. If the first attempt
succeeded, then the source file must also be gone.

Pick-to: 6.6 6.5 6.2 5.15
Fixes: QTBUG-117383
Done-With: Thiago Macieira <thiago.macieira@intel.com>
Change-Id: Icb82a0c9d3b337585dded622d6656e07dee33d84
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-09-24 14:10:56 -07:00
Giuseppe D'Angelo
6c504f2519 QPointer: also provide a converting assignment operator
d026fad3d9 added converting constructors
for QPointer. This however made converting _assignments_ ambiguous,
introducing a regression for users coming from Qt < 6.6.

This code:

  QPointer<Base> base;
  QPointer<Derived> derived;
  base = derived;

used to convert `derived` to `Derived *` (using the implicit conversion
operator from `QPointer<Derived>` to `Derived *`), and then the
assignment operator for `QPointer<Base>` that took a `Base *`.

The introduction of the conversion constructor in 6.6 makes it possible
to convert `QPointer<Derived>` to `QPointer<Base>`, and then fall back
to the compiler-generated assignment operator for `QPointer<Base>`.

The result is that the code above is now ambiguous and stops compiling.

Fix this by adding a converting assignment operator for QPointer.
I'm only adding the const-lvalue overload because the implementation
requires going through the private QWeakPointer::assign helper. We
cannot copy-assign or move-assign the inner QWeakPointer, as those
assignments require lock()ing the QWeakPointer and that's not possible
on a QObject-tracking QWeakPointer (but cf. QTBUG-117483).

Assigning from a rvalue QPointer would mean calling assign() on
the internal QWeakPointer _and_ clear the incoming QPointer,
and that's strictly worse than the lvalue overload (where we just call
assign()).

Change-Id: I33fb2a22b3d5110284d78e3d7c6cc79a5b73b67b
Pick-to: 6.6 6.6.0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-23 22:10:10 +00:00
Thiago Macieira
610b26b819 tst_QFile::moveToTrash: include the test name in the tempfile templates
Makes it easier to locate later which test may be leaking stuff.

Pick-to: 6.6
Change-Id: I9d43e5b91eb142d6945cfffd178713f869752761
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-09-23 08:18:24 -07:00
Thiago Macieira
772ad60425 Q{Temporary,}File: make QStandardPaths use test mode
The moveToTrash tests, on XDG platforms, would be trashing to
~/.local/share/Trash. Unlike Windows and Apple systems, the XDG trash
spec creates two files and these tests weren't deleting both of them, so
we had a slow increase of left-over files in ~/.local/share/Trash/info.

Cleaning up ~/.qttest is left as an exercise for the users. For example,

 $ cat ~/.config/user-tmpfiles.d/qttest.conf
 #Type Path                            Mode User Group Age         Argument
 e     %h/.qttest                      0700 -    -     1w

Pick-to: 6.6 6.5 6.2
Change-Id: I9d43e5b91eb142d6945cfffd1786aeff91d34fde
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-09-23 08:18:21 -07:00
Tor Arne Vestbø
201045a1fd Remove remnants of Qt for Native Client (NACL)
The project has been superseded by Qt for WebAssembly and was
never supported in Qt 6.

Pick-to: 6.6 6.5
Change-Id: I36682cfe3ce6adac76a307b0faba97dcb7c655cc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-23 13:40:44 +02:00
Volker Hilsheimer
941f49b018 JNI: treat enums as their underlying types
Android APIs use integer constants like enum values, so they are mapped
to one of the integeral types (jint, jshort, jlong etc) on the C++ side.
Enable C++ code to declare an equivalent enum (scoped or unscoped), and
to use that enum as a type in JNI calls by treating it as the underlying
type in the signature() generator.

Add a helper type trait that maps enums to their underlying type and
other integral types to themselves (we can't use std::underlying_type_t
on a non-enum type). Add tests.

Note: Java Enums are special classes with fields; this change does not
add any special support for those.

Change-Id: Iec430a1553152dcf7a24209aaebbeceb1c6e38a8
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2023-09-23 07:24:26 +02:00
Volker Hilsheimer
c4a8c2b0d0 Silence compiler warning
Don't get a QModelIndex out of a temporary QPersistentModelIndex.

Pick-to: 6.6
Change-Id: Ida9e25f1a17130e19b75221e1189e6f2fccd3f27
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
2023-09-22 20:40:36 +02:00
Alexandru Croitor
bf2587d9e5 CMake: Update the ios assets manual test
- provide an asset catalog .json file for both Xcode 13 and 14
  formats. Apps built against the Xcode 13 SDK are not validated
  anymore by the App store, but it's still useful to see how things
  were before.

- Xcode 13 required the following icon sizes for a universal iOS app:
   60x60@2x, 76x76@2x\~ipad, 167x167, 1024x1024

- Xcode 14 only needs the 1024x1024 one

- icons need to be embedded into the asset catalog starting with iOS
  11 according to Apple docs (not sure which Xcode version, but it's
  needed for both Xcode 13 and Xcode 14), and they don't have to
  manually be copied into the bundle anymore, Xcode takes care of
  that when processing the asset catalog

- add an 167x167 icon image for the iPad pro for Xcode 13

- add an 1024x1024 icon image that is required for successful app store
  submission and embed it into the asset catalogs

- for Xcode 13, we need to manually specify all the required icon
  sizes

- for Xcode 14 we can rely on Xcode to generate the smaller icons from
  the big one

- because the icons need to live in the asset catalog folder, remove
  unnecessary icons in the appicons folder.

- for the cmake project, make sure the asset catalog compiler generates
  the icons by setting the
  XCODE_ATTRIBUTE_ASSETCATALOG_COMPILER_APPICON_NAME attribute
  qmake does automatically already.
  it would be nice if we can do that automatically in a future Qt
  version

- remove unused icon references in Info.plist file with Xcode 13

- remove all icon references in Info.plist with Xcode 14, rely on Xcode
  to add that info via its generated partial Info.plist file that gets
  merged into the main one.

- don't include CMakeLists.txt as a text resource

Amends cf3535fdf2

Pick-to: 6.5 6.6
Task-number: QTBUG-104519
Task-number: QTBUG-110921
Task-number: QTBUG-116784
Change-Id: I0bc556e66647a66bc21402ea62db3374d0970e97
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-09-22 20:40:36 +02:00
Alexandru Croitor
370962315a CMake: Fix incorrect UILaunchStoryboardName value in Info.plist
The value needs to be 'CustomLaunchScreen', not
'CustomLaunchScreen.storyboard', otherwise app store validation will
fail with the following error:

 Asset validation failed
 Invalid bundle. Because your app supports Multitasking on iPad, you
 need to include the CustomLaunchScreen.storyboard launch storyboard
 file in you bundle. Use UILaunchScreen instead if the app’s
 MinimumOSVersion is 14 or higher and you prefer to configure the
 launch screen without storyboards.

This brings the value in line with what we have for the qmake
Info.plist file.

Amends cf3535fdf2

Pick-to: 6.5 6.6
Task-number: QTBUG-104519
Task-number: QTBUG-110921
Task-number: QTBUG-116784
Change-Id: I4e9cc2ed685634544955e967f35fdc426dac0f0c
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-09-22 20:40:36 +02:00
Alexandru Croitor
528e70b6d9 CMake: Add CFBundleIconName key to ios assets manual tests
It is required for publishing an app to the app store. Otherwise during
app store validation phase, you get an error:

 Asset validation failed
 Missing Info.plist value. A value for the Info.plist key
 'CFBundleIconName' is missing in the bundle 'foo'. Apps built with
 iOS 11 or later SDK must supply app icons in an asset catalog and must
 also provide a value for this Info.plist key.
 For more information see
 http://help.apple.com/xcode/mac/current/#/dev10510b1f7.

Note this is not needed when using Xcode 14.3+ and when one places the
icons into an asset catalog. When processing icons in the asset
catalog, Xcode generates a partial Info.plist file that will contain
the CFBundleIconName key and will merge into the final Info.plist
file.

Amends cf3535fdf2

Pick-to: 6.5 6.6
Task-number: QTBUG-104519
Task-number: QTBUG-110921
Task-number: QTBUG-116784
Change-Id: I53009097cf27b096c72ee9c4bad6aa4286272061
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
2023-09-22 20:40:35 +02:00
Volker Hilsheimer
cf0bd543d6 QJniObject: add callStaticMethod overload that takes class as type
Equivalent to get/setStaticField.

Add a test, and tighten up the surrounding test code a bit.

Change-Id: Ic0993c5d6223f4de271cb01baf727459b5167f94
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
2023-09-22 07:18:21 +02:00
Volker Hilsheimer
e1a349983c JNI: move signature/className template functions into a template class
Template functions don't permit partial specialization, e.g. we cannot
specialize typeSignature() to return an array signature for any
std::vector or QList type. We need to do that for better array support,
so move those functions as static members into a template class, which
then can be specialized.

Since submodules are both calling and specializing typeSignature and
className as template functions, keep and use those until the porting is
complete.

Change-Id: I74ec957fc41f78046cd9d0f803d8cc9d1e56672b
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
2023-09-22 07:18:16 +02:00
Volker Hilsheimer
0022b05a9a JNI: rename our compile-time String type to CTString
The type lives in the QtJniTypes namespace, which is where types end up
that are declared through the Q_DECLARE_JNI_CLASS/TYPE macros. Having a
String type in that namespace prevents us from declaring the Java String
class as a QtJniTypes type, which is silly.

Perhaps this type becomes obsolete at some point with std::string being
a constexpr type in C++23, but until then we need it. It has no ABI, so
renaming it us safe.

Until submodules are ported, leave a compatibility alias String type,
which also prevents us from declaring a String JNI class in tests until
the alias is removed in a later commit.

Change-Id: I489a40a9b9e94e6495cf54548238438e9220d5c1
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
2023-09-22 07:18:10 +02:00
Volker Hilsheimer
dc126de22e QItemSelectionModel: don't warn when destroying the model
Amends 4f4a8e75ab, after which
QItemSelectionModel printed a warning when destroying the model.
We reset the selection model in response to the model getting destroyed,
and since the model is already set to be nullptr at this point the
select() function complains about changing the selection with no model
set being a no-op.

Fix this by not calling reset() when the model gets destroyed - the
stored selection and currentIndex are already reset at this point -
and instead only call reset() when a new model is set in initModel.

Fixes: QTBUG-117200
Pick-to: 6.6.0 6.6 6.5 6.2
Change-Id: I12fc6b3fb2f2ff2a34b46988d5f58151123f9976
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
2023-09-22 01:42:45 +02:00
Aleix Pol
52a5a89ea4 QCommandLineParser: Warn invalid value calls
If the QCommandLineOption doesn't have a valueName, the parser won't
read the argument, therefore returning an empty value. If the developers
are calling ::value on the option, they clearly think it's expected to
get a value but won't ever be getting one, so we better warn them about
it.

Change-Id: I434b94c0b817b5d9d137c17f32b92af363f93eb8
Reviewed-by: David Faure <david.faure@kdab.com>
2023-09-21 22:05:06 +02:00
Joerg Bornemann
814de4c2ce CMake: Fix config condition evaluator
Use recursive descent to handle parentheses in config condition
expressions. This fixes cases like 'NOT (A AND B)'.

Fixes: QTBUG-117053
Change-Id: Iab1b6173abe00d763808bb972a9a5443ffa0938d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
2023-09-21 21:46:46 +02:00
Volker Hilsheimer
6c90aa029b QDockWidget: ignore close event if DockWidgetClosable is not set
[ChangeLog][QtWidgets][QDockWidget] A floating dockwidget that doesn't
have the DockWidgetClosable feature flag set can no longer be closed by
a call to QWidget::close or a corresponding keyboard shortcut (such as
Alt+F4).

Fixes: QTBUG-116752
Pick-to: 6.6 6.5
Change-Id: I7859a2eed11f0e4ee013f7f56611e282e9bcae9a
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-09-21 18:36:06 +02:00
Joerg Bornemann
36e043dde6 CMake: Add autotest for the config condition evaluator
This serves as regression test for future fixes of the config condition
evaluator.

Task-number: QTBUG-117053
Change-Id: Ib05fe5f5fb6aa2d440ecbc8affaf99b040553c06
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
2023-09-21 17:00:22 +02:00
Marc Mutz
dee68587d5 Update public suffix list
Version 1a4824549b093abc3077205ae5386ed57f73806d, fetched on
2023-09-20.

Pick-to: 6.6 6.6.0 6.5 6.5.3 6.2 5.15
Fixes: QTBUG-117138
Change-Id: If288d7fce714384a0132261303de31ad2299c239
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-09-20 22:33:18 +02:00
Eskil Abrahamsen Blomfeldt
5469d6a6cc Support loading variable fonts as application fonts in Freetype
When loading the fonts, we go through all the named instances
and register these as subfamilies. In addition to exposing these
variants by style name, we also register them with the according
weights, italic style and stretch. This adds a field to FontFile
to allow piping the instance index through to when we instantiate
the face.

[ChangeLog][Fonts] Added support for selecting named instances in
variable application fonts when using the Freetype backend.

Task-number: QTBUG-108624
Change-Id: I57ef6b4802756dd408c3aae1f8a6c792a89bee6a
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
2023-09-20 21:37:50 +02:00
Øystein Heskestad
13f673939d Fix renamed and duplicated namespaces in QXmlStreamWriter
The XML stream writer previously added namespace declarations with the
same URL as existing ones, but new names, and renamed the XML elements
to use the new namespaces instead of the existing ones.

[ChangeLog] Fix renamed and duplicated namespaces in QXmlStreamWriter.

Pick-to: 6.5 6.6
Fixes: QTBUG-75456
Change-Id: I90706e067ac9991e9e6cd79ccb2373e4c6210b7b
Done-With: Philip Allgaier <philip.allgaier@bpcompass.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-09-20 17:16:29 +02:00
Marc Mutz
10d915277e tst_QStringBuilder: update the warning re:includes in stringbuilder.cpp
Not only are we subject to Q and P defines, we're also included in the
unnamed namespace now.

Amends df030e06a8.

Pick-to: 6.6
Change-Id: Ie2f4c9f45d9845d8a26140e0e1214e87b615ff02
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-20 17:16:28 +02:00
Hatem ElKharashy
8dee03500e Add Manual test for Graphics Frame Capture
Simple window with a rotating rectangle that can be
captured using QGraphicsFrameCapture.

Task-number: QTBUG-116146
Change-Id: Ia3b6928e469d926c53260ee40ed5af97dd280c08
Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
2023-09-20 10:51:55 +03:00
Giuseppe D'Angelo
4a6cbfbe5c QVariant: add fromMetaType
The QVariant(QMetaType) constructor is a major anti-pattern: unlike
*every* other QVariant's constructor, it doesn't build a QVariant
holding the QMetaType object, but a QVariant of the specified type.

Introduce a named constructor for this use case instead.

In principle, this should lead to a deprecation of the QMetaType
constructor... except that it's used everywhere, so I can't do it at
this time.

Drive-by, improve the documentation of the QVariant(QMetaType)
constructor (since it's basically c&p for the new fromMetaType
function).

[ChangeLog][QtCore][QVariant] Added the QVariant::fromMetaType named
constructor, that builds a QVariant of a given QMetaType.

Change-Id: I4a499526bd0fe98eed0c1a3e91bcfc21efa9e352
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-09-20 00:05:53 +02:00
Volker Hilsheimer
7f4cdb9941 JNI: replace TYPE declarations with CLASS declarations
That we have two macros to declare a C++ type to represent a Java class
is confusing. The TYPE macro as of now allows us to declare array types,
but with QJniArray we won't need that anymore, and can just use Class[]
as the type instead. Changing that will be a follow-up commit; for now,
get rid of TYPE-usages to declare regular classes.

Change-Id: Iea0a9548772ca701148442412cf6ad567583213f
Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
2023-09-20 00:05:39 +02:00
Thiago Macieira
9edb835904 IPC: Move the legacy key to the QNativeIpcKey
This is needed to support passing it to other processes so they can
enable legacy, compatibility mode. Right now, there's no such code, but
I am 90% certain we'll need it soon in 6.6.x, if not for compatibility
changes in the future.

There's a bug in passing a QNativeIpcKey to another process that causes
QSharedMemory to use the wrong QSystemSemaphore for control (a feature
that should never have existed in the first place, but we're 15 years
too late on that). I have not yet investigated a fix for this, but it
will likely involve knowing the original legacy key.

Pick-to: 6.6 6.6.0
Change-Id: Idd5e1bb52be047d7b4fffffd1750b547013cb336
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-09-17 18:10:18 -07:00
Thiago Macieira
18867845eb IPC: disallow unknown queries in QNativeIpcKey string form
So we can add them in the future but cause older versions of Qt to
reject them if they don't know what they are.

Pick-to: 6.6 6.6.0
Change-Id: I512648fd617741199e67fffd1782b85935bb832a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-09-17 18:10:18 -07:00
Edward Welbourne
9c0def81e4 Warn on failure to construct valid system time zone object
Also move some docs from asBackendZone() to systemTimeZone(), making
clear that the system zone object is current at the time of creation
and won't be updated if the system is reconfigured. Adapt some tests
to fail and make clear that the system is misconfigured if no valid
system zone is found.

[ChangeLog][QtCore][QTimeZone] If systemTimeZone() is unable to
identify a valid system time zone, it now produces a warning the first
time it encounters the problem.

Task-number: QTBUG-116017
Change-Id: Ia437d8a03ff3cbf2b2cd98e8a8c3aebe50c1ee32
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-15 21:53:36 +02:00
Arno Rehn
ba2ebc24a1 QtFuture: Prevent whenAll()/whenAny() from creating reference cycles
whenAll() and whenAny() create a shared context object which is
referenced by the continuation lambda. The refcount of context is only
correctly managed when it is copied non-const to the lambda's
capture list.

Fixes: QTBUG-116731
Pick-to: 6.6 6.6.0
Change-Id: I8e79e1a0dc867f69bbacf1ed873f353a18f6ad38
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-09-15 13:36:15 +00:00
Giuseppe D'Angelo
d184f4153c QDBusMarshall test: avoid an atomic assignment
There's no need for atomic semantics for a simple "scope value
rollback" (not sure why the code doesn't use the real thing).
There's also no semantics that make sense.
Extract the integer out of the atomic and store it back.

Change-Id: I8ba89216d1931a73ff22a8af7fd656c3f6948793
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 18:39:24 +02:00
Marc Mutz
16433a4a6e Long live Q_(U)INT128_C()!
Compilers that support 128-bit integer types usually don't have
support for 128-bit literals, so provide Q_(U)INT128_C macros and back
them with UDLs. This, of course, only works in C++, so until compilers
provide built-in literals that support C, too, that's all we get.

[ChangeLog][QtCore] Added Q_INT128_C() and Q_UINT128_C() macros to
create qint128 and quint128 literals in a platform-independent way.

Pick-to: 6.6 6.6.0
Fixes: QTBUG-116822
Change-Id: I4be645baf2e007ee1aa1a27f9b5166671806dc49
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-14 18:39:24 +02:00
Piotr Wierciński
9468ef2cfb CI: Enable some tests under corelib/thread for Wasm platform
This is part of our testing effort where we try enabling more tests for
Web Assembly platform on CI. Not all tests work out of box, so some of
them will require followup work.
This commmit also introduces a new mechanism of automatically renaming
files when they are added many times with the same filename to single
translation unit.

Change-Id: I620536494ea83aeb9b294c4a35ef72b51e85a38b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
2023-09-14 11:58:48 +02:00
David Faure
549ed4fb24 QMimeType: simplify implementation of filterString
As suggested by Ahmad Samir

Change-Id: I7f3ef29436a7725b6dceab72bd0f8b01756bf930
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-13 23:27:44 +02:00
David Faure
1f0bc1ade3 QMimeDatabase: fix glob-deleteall support for the binary providers
This fixes the recently added QEXPECT_FAIL about glob-deleteall
in a local directory (with a binary cache). Before adding a glob match
we ask the more-local (higher-precedence) directories if they have
a glob-deleteall for that mimetype, and skip it then. This "asking"
is a virtual method, implemented for both XML and binary providers.

Change-Id: I6e4baf0120749f3331fd2d9254bea750a322b72d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-13 23:27:44 +02:00
Edward Welbourne
c0cb616c1d Use the modern name for zone Asia/Kolkatta
The old name Asia/Calcutta is being phased out. We can't assign
QTzTZP, so select between new name and old using a reference variable.
In the process, fix a QCOMPARE() against bool to a QVERIFY().

Pick-to: 6.6 6.5
Change-Id: I7cd8a813f8a88c8ae4ba07213f04f4ad0860cec0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-13 19:51:47 +02:00
David Faure
4e9944e6c8 QMimeDatabase: collect glob patterns from all locations
A QMimeTypePrivate used to belong to a single provider, which would
provide the complete data for it.
But since the redesign in commit 7a5644d648, each provider
represents is a single mime directory, and the merging happens at the
QMimeDatabase level. So we need a QMimeType[Private] to be just a name
(a "request" for information about this mimetype) and the information
for that mimetype is retrieved on demand by querying the providers
and either stopping at the first one (e.g. for icons) or merging
the data from all of them (e.g. for glob patterns).

The XML provider was using QMimeTypePrivate as data storage,
give it its own struct QMimeTypeXMLData for that purpose instead.

Task-number: QTBUG-116905
Change-Id: Ia0e0d94aa899720dc0b908f40c25317473005af4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-13 13:45:04 +02:00
David Faure
994311a66b tst_qmimedatabase: move local override to the specific test method
When running tst_qmimedatabase with the full shared-mime-info test suite
(which unfortunately requires local setup so this is easy to overlook),
we need *.webm to still be associated with video/webm.

So to test glob-deleteall, do that in installNewLocalMimeType(), with
other similar tests.

This however unearthed the following bug: the handling of glob-deleteall
is only correct when the local dir has no binary cache. It's broken
when using a binary cache. Added a QEXPECT_FAIL for now because this is
going to be fixed as part of a major redesign, coming up.
I also found out that neither xdgmime nor gio do this correctly...

Change-Id: Ib075fcdb792f60a859f23db8c2d7e1c6524f9050
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-13 13:45:04 +02:00
David Faure
251ab925fe tst_qmimedatabase: separate xml files for Global and Local tests
For historic reasons, the test had a single list of override xml files
to copy first into the global dir, and then into the local dir.
But glob-deleteall only makes sense in the local dir (as per the MIME
spec). Having two definitions for the same mimetype in the same dir
is undefined behavior, so the test was working by chance only, and
my upcoming refactoring/fixes caught that.

Change-Id: I4717683b4b3f9ba69f1fd815669460789700e877
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-09-13 13:45:04 +02:00