If one needed to listen to a signal just once, one had to
store the QMetaObject::Connection object returned by connect()
and use it to disconnect the slot after the first signal
activation.
This has led to a proliferation of using wrappers (and enough
TMP); they usually look like this:
1) create a shared_ptr<QMO::Connection>, allocating its payload;
2) create a lambda, capturing the shared_ptr by value;
3) in the lambda, disconnect the connection (through the shared_ptr),
and call the actual slot;
4) connect the signal to the lambda, storing the returned
QMO::Connection into the shared_ptr.
This is expensive, error prone for newcomers, and tricky to
support as a general facility inside one's projects.
We can do better, just support single shot connections right
in QObject.
[ChangeLog][QtCore][QObject] Added the Qt::SingleShotConnection
flag. When a connection is established with this flag set,
the slot is going to be activated at most once; when the signal
is emitted, the connection gets automatically broken by Qt.
Change-Id: I5f5feeae7f76c9c3d6323d841efba81c8f98ce7e
Fixes: QTBUG-44219
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
One could guess it by assuming that disconnecting for a destroyed
receiver and disconnect() with given receiver use the same
implementation, but without closely knowing the implementation a
reader of the documentation can't know for sure.
Also add a test to prove that what the new documentation says is
really true.
Also remove an unnecessary negation in the preceding sentence.
Change-Id: I9d24442bb1a4646b89f969bad1a4d0e1eafa7534
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This is in line with QMetaType and will be used to implement a mutable
QSequentialIterable. Later on, a QMetaAssociation will be added as
well, to implement a mutable QAssociativeIterable.
The code here represents the minimal set of functionality needed to have
a practical sequential container. The functionality is not completely
orthogonal. In particular, the index based operations could be
implemented in terms of iterator-based operations.
Task-number: QTBUG-81716
Change-Id: Ibd41eb7db248a774673c701549d9a03cbf2e48b6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
When a signal/slot connection is activated, a lock on the receiver
object is taken (to be sure it doesn't get destroyed).
The path for blocking queued connections however took the lock on
the sender by accident, fix that.
Pick-to: 5.15 5.12
Change-Id: I8cd938a50eca2bf71e7bfb86768ee0c8431afdfa
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
We need to add these two classes at the same time, because
QAnyStringView makes all QUtf8StringView relational operators moot. We
might want to add some later, esp. for UTF-8/UTf-8 comparisons, to
avoid the pessimization that we can't early-out on size() mismatch in
QAnyStringView equality operators, but that's an optimization, not a
correctness issue, and can be fixed in a source-compatible way even
after Qt 6 is released.
To deal with the char8_t problem in C++20, make QUtf8StringView a
class template out of which two UTF-8 views can be instantiated: the
Qt 7 version, which depends on C++20 char8_t as value_type, and the Qt
6 version where value_type is a char. Use inline namespaces to map the
QUtf8StringView identifier to one or the other, depending on the C++
version used to compile the user code. The inline namespace names must
needs be a bit ugly, as their inline'ness depends on __cpp_char8_t. If
we simply used q_v1/q_v2 we'd be blocking these names for Qt inline
namespaces forever, because it's likely that inline'ness of other
users of inline namespaces in Qt depends on things other than
__cpp_char8_t. While inline'ness of namespaces is, theoretically
speaking, a compile-time-only property, at least Clang warns about
mixed use of inline on a given namespace, so we need to bite the
bullet here. This is also the reason for the QT_BEGIN_..._NAMESPACE
macros: GCC is ok with the first declaration making a namespace
inline, while Clang warns upon re-opening an inline namespace as a
non-inline one.
[ChangeLog][QtCore][QUtf8StringView] New class.
[ChangeLog][QtCore][QAnyStringView] New class.
Change-Id: Ia7179760fca0e0b67d52f5accb0a62e389b17913
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
High-DPI pixmaps are always enabled, and cannot be disabled.
Change-Id: I01a006b404e5431582b64ef812974c1c022b39ae
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Since 5.0: assignment/construction from QObject pointer
Since 5.14: data() to recover the packaged pointer
Change-Id: I5d6ab561ce39bc0d9d3e5035eb2ca38139cd76b6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
The Unicode table code can only be safely called on valid code-points.
So code that calls it must only pass it valid Unicode data. The string
iterator's Unchecked Unchecked methods only provide this guarantee
when the string being iterated is guaranteed to be valid UTF-16; while
client code should only use QString, QStringView and friends on valid
UTF-16 data, we have no way to be sure they have respected that.
So take the few extra cycles to actually check validity in the course
of iterating strings, when the resulting code-points are to be passed
to the Unicode table look-ups. Add tests that case mapping doesn't
access Unicode tables out of range (it'll trigger the new assertion).
Added some comments to qchar.h that helped me understand surrogates.
Change-Id: Iec2c3106bf1a875bdaa1d622f6cf94d7007e281e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Port the high-dpi icon test to use the new pixmap()
API which takes the target devicePixelRatio as an argument.
This means we can run the fromTheme test at dpr = {1,2,3},
instead of at the current global devicePixelRatio only.
Task-number: QTBUG-85885
Change-Id: Iec7b21e04ed760e48964307d2048eaec1976ffe2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Add Q_REQUIRED_RESULT to force callers to check the return; the
QTranslator object is unusable if load() fails.
Check the result in QTranslator's own test.
Task-number: QTBUG-85700
Change-Id: I07509c76470cc87626190670665cd3162bfb17e7
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
A large slice of it has been deprecated since 5.2.
Reflowed a doc paragraph pointed out, in the deprecation commit, as
having been left ragged by its edits.
Note: qSwap() is documented as \deprecated but not marked, where it's
defined, as deprecated.
Change-Id: Iaff10ac0c4c38e5b85f10eca4eedeab861f09959
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This attribute is now on by default.
Change-Id: I7c9d2e3445d204d3450758673048d514bc9c850c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
The functionality should be available via QWidget::winId(),
and QWidget::createWindowContainer() + QWindow::fromWinId().
Any bugs in this area should be fixed by improving the general
wrapping APIs.
Fixes: QTBUG-83254
Change-Id: I86584a4a8138d17d65a50da39efd58039f10da91
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Without an override for logicalDpi() the base class implementation
would use the geometry of the screen to figure out the DPI, and end
up with ~100, which combined with a 96DPI base logical DPI would
give a wrong scale factor.
Change-Id: I68aecce44d2ee672c7b707dfe5444af8f551e961
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
warning: all paths through this function will call itself [-Winfinite-recursion]
Change-Id: I70008710a7448ffd532bb6c3acb488fe439cb807
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
It was left out of the build in f08038fca7
but not removed. It doesn't make sense to keep it, as the classes it
tests have been removed.
Change-Id: Ic36a066eb092d8b9b40c645de649af9dcaab4ff2
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
PCRE2 already uses size_t which we can now make full use of.
Change-Id: Icb5efd5c6ef27f2e31a9780bf62f5671ddc603cd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
As there is now a chance that a QMetaMethod already contains the
metatypes for its arguments, we can just query it directly (and use the
fallback to name lookup logic that already exists there).
This also allows us to avoid creating a QList of names, and only
requires us to do a name lookup in case the connection actually fails.
Change-Id: Idda30bc4b538a94476ae6c533776c22340f0030d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
While we initially wanted to just disable the functionality the way it
is currently built forces people to do a full build of Qt just to enable
it. Instead of doing this half-measure let's just remove the code
completely from QtBase and rather prepare QtNetwork to handle being a
plugin that can be compiled at any time.
Task-number: QTBUG-80340
Change-Id: I19155c8c167cf932088f01b2a9706d0e7ab792d1
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
I don't think we want to have implicit conversion
from a const char * or a QByteArray to a QUuid.
Change-Id: Idfe7450ce15b89e295aa7af7ccf1fc94f5acd4f9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Restored previously deleted logic of setting GrowsBackwards flag for
prepend-like cases. This should be sufficient to fully enable prepend
optimization
Fixed QList::emplace to not use implementation detail logic. Updated
tests to cover changed behavior and its correctness
Task-number: QTBUG-84320
Change-Id: I4aadab0647fe436140b7bb5cf71309f6887e36ab
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Introduced prepend optimization logic to QCommonArrayOps.
Trying to rely on original QList behavior
Task-number: QTBUG-84320
Change-Id: I46e6797b4edad804a3e3edb58307c9e96990fe01
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Introduced allocation function in QArrayDataPointer with
interface similar to QArrayData::allocate that supports growing
strategies. This func is used instead of the original in cases
when prepend-aware storage is needed. Tried to follow Qt5 QList
policy in terms of space reservation
Updated QPodArrayOps::reallocate to be aware of growing
shenanigans. It doesn't look like a perfect solution but it is
rather close and similar to what Qt6 QList is doing when not
growing (e.g. reserve/squeeze)
Added initial QCommonArrayOps with helper function that tells
when reallocation is preferable over just using the insert-like
operation. This comes up later on when GrowsBackwards policy is
properly supported in operations
Essentially, 2/3 main data management blocks for prepend optimization
are introduced here. The last one being a generalized data move that
is done instead of reallocation when existing free space is not enough
Task-number: QTBUG-84320
Change-Id: I9a2bac62ad600613a6d7c5348325e0e54aadb73d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
A comment is not good enough, Some of the enum members were even still
in use, or mentioned in documentation.
WA_ContentsPropagated, WA_WState_DND and WA_ForceAcceptDrops have been
deprecated since 4.5.1; and at least the last has been an \omitvalue
in the docs for even longer. (WA_ShowModal and WA_GroupLeader have
been similarly marked, but are in use, see QTBUG-85816.)
Push back to 5.15.1 in order to be able to remove these at Qt 6.
Pick-to: 5.15.1
Change-Id: I6ea3839767e5f5158b0fed508f65798470191908
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Add new QIcon::pixmap() overload:
QPixmap pixmap(const QSize &size, qreal devicePixelRatio, ...)
This function replaces the existing pixmap() function which
take a QWindow pointer, and should be more convenient in use.
Task-number: QTBUG-85885
Change-Id: Ie4ca96a266d9278864678dc61bdfc2836cabdb93
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
viewOptions returned a QStyleOptionViewItem object. Such a method
can never support newer versions of the option structure.
Most styleable QWidget classes provide a virtual method
initStyleOption that initializes the option object passed in as a
pointer, e.g QFrame, QAbstractSpinBox, or QComboBox.
Follow that API convention, but name it initViewItemOption, as the
QStyleOptionViewItem struct contains information about the item as
well as the widget itelf.
This is a source incompatible change that will go unnoticed unless
existing subclasses mark their overrides as 'override', or call
the removed QAbstractItemView::viewOption virtual function.
[ChangeLog][QtWidgets][QAbstractItemView] The virtual viewOptions
method that previously returned a QStyleOptionViewItem object has
been renamed to initViewItemOption, and initializes a
QStyleOptionViewItem object that's passed in through a pointer.
Change-Id: Ie058702aed42d77274fa3c4abb43ba302e57e348
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
The explicit paint event on QtGui and QPA level allows us to untangle
the expose event, which today has at least 3 different meanings.
It also allows us to follow the platform more closely in its semantics
of when painting can happen. On some platforms a paint can come in
before a window is exposed, e.g. to prepare the first frame. On others
a paint can come in after a window has been de-exposed, to save a
snapshot of the window for use in an application switcher or similar.
The expose keeps its semantics of being a barrier signaling that the
application can now render at will, for example in a threaded render
loop.
There are two compatibility code paths in this patch:
1. For platform plugins that do not yet report the PaintEvents
capability, QtGui will synthesize paint events on the platform's
behalf, based on the existing expose events coming from the platform.
2. For applications that do not yet implement paintEvent, QtGui will
send expose events instead, ensuring the same behavior as before.
For now none of the platform plugins deliver paint events natively,
so the first compatibility code path is always active.
Task-numnber: QTBUG-82676
Change-Id: I0fbe0d4cf451d6a1f07f5eab8d376a6c8a53ce8c
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Change the name/key of the style to 'macos'. Besides the
name 'macintosh' being archaic, we also need this
change to avoid creating 'macintosh' style folders
in QtQuickControls, now that we plan to use QPlatformTheme
also there to resolve the style.
[ChangeLog][Widgets][QStyle] The 'macintosh' style
has been renamed to 'macos'.
Change-Id: I14b8a8b4dbd369e7a7d16b94e4ad27e501e7e8d0
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Currently QFuture::waitForFinished() exits as soon as the future is not
in the running state. If the user calls it before
QPromise::reportStarted() is called, it will exit immediately, because
nothing is running yet. Fix the behavior to wait for the finished state.
[ChangeLog][Important Behavior Changes][QtCore] Fixed the behavior of
QFuture::waitForFinished() to wait until the future is actually in the
finished state, instead of exiting as soon as it is not in the running
state. This prevents waitForFinished() from exiting immediately, if at
the moment of calling it the future is not started yet.
Task-number: QTBUG-84867
Change-Id: I12f5e95d8200cfffa5653b6aa566a625f8320ca8
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
QString still has the overloads of relational operators taking
QByteArray. Add back QByteArray's relational operators taking
QString for symmetry. See also the comments of
d7ccd8cb45 for more details.
[ChangeLog][EDITORIAL] Remove the changelog about QString/QByteArray
operators being removed. They're back.
Change-Id: I22c95e727285cf8a5ef79b3a4f9d45cb66319252
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
QCoreApplication has a special internal mechanism to control whether
the event dispatcher should block after delivering the posted events.
To handle queued connections in nested loops properly, we should use
that functionality.
Pick-to: 5.15
Fixes: QTBUG-85981
Change-Id: I124179a23b26a995cf95ed379e97bfa62c95f42a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
The test explicitly asks for a non-native file dialog, which works on
macOS as well.
Change-Id: I964c6d98501b4207c2b6c2ce1df39f654c801a43
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
First, use QT_MKDIR instead of QFileSystemEngine::createDirectory(), as
the latter can't create a directory with the right permissions. That
would allow an attacker to briefly obtain access to the runtime dir
between the mkdir() and chmod() system calls.
Second, make sure that if the target already exists that it is a
directory and not a symlink (even to a directory). If it is a symlink
that belongs to another user, it can be changed to point to another
place, which we won't like.
And as a bonus, we're printing more information to the user in case
something went wrong. Sample outputs:
QStandardPaths: runtime directory '/root' is not owned by UID 1000, but a directory permissions 0700 owned by UID 0 GID 0
QStandardPaths: runtime directory '/dev/null' is not a directory, but a character device, socket or FIFO permissions 0666 owned by UID 0 GID 0
QStandardPaths: runtime directory '/etc/passwd' is not a directory, but a regular file permissions 0644 owned by UID 0 GID 0
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-tjmaciei'
QStandardPaths: runtime directory '/tmp/runtime-tjmaciei' is not a directory, but a symbolic link to a directory permissions 0755 owned by UID 1000 GID 100
Pick-to: 5.15 5.12 5.9
Change-Id: Iea47e0f8fc8b40378df7fffd16248b663794c613
Reviewed-by: David Faure <david.faure@kdab.com>
This doesn't give useful defaults on all platforms; icon themes are not
provided on platforms other than Linux, and the mime database doesn't
always return user-friendly names based on file names.
However, both icon themes and the mime database can be customized by
application developers by shipping a data file side-by-side with the
application, without the need for reimplementing the provider class.
Change-Id: Ie4b18ac1b861e2da64f01d1f209986b27fbe6bd5
Task-number: QTBUG-66177
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
The convenience API used to look up the index of a named capturing
group expects NUL terminated strings. Therefore, we can't just
use it together with QStringViews, which may be not. Use the
non-convenience API instead.
Pick-to: 5.15
Change-Id: I25ca14de49b13ee1764525f8b19f2550c30c1afa
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Remove QTypeInfo::isStatic, as that's not used anymore in Qt 6.
Also remove sizeOf, it's unused, and we have QMetaType for that if
required.
Remove all typeinfo declaractions for trivial types, as the default
template covers them correctly nowadays.
Finally set up a better default for isPointer, and do some smaller
cleanups all over the place.
Change-Id: I6758ed37dfc701feaaf0ff105cc95e32da9f9c33
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Having three methods with the same name doing different things is
unnecessarily confusing, so follow the standard naming convention in
Qt and call the getter of the resolve mask resolveMask, and the setter
setResolveMask. These methods were all documented as internal.
The publicly documented resolve() method that merges two fonts and
palettes based on the respective masks remains as it is, even though
'merge' would perhaps be a better name.
Change-Id: If90b1ad800834baccd1dbc38fc6b861540d6df6e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
It wouldn't grab the cached entry since it was not deemed
"fresh" (and would never be fresh because we didn't know when it
originated from or when it expired). But the test still passed because
the reply produced a "finished" signal which ended the loop, but the
"finished" signal was due to an error which was unchecked.
Change-Id: I6ad271aa621bdb4a48b74bc8fd64c7e2caa8f179
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>