Commit Graph

14557 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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