summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobjectdefs.h
Commit message (Collapse)AuthorAgeFilesLines
* Add QChronoTimer, a timer with nanoseconds precisionAhmad Samir2024-03-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The interval in QTimer is a QProperty of type int, which means it's limited to the number of milliseconds that would fit in an int (~24 days), this could cause overflow if a user constructs a QTimer with an interval > INT_MAX milliseconds. And it can't be easily changed to use qint64/std::chrono::nanoseconds: - changing the getters to return qint64 means user code would have narrowing conversions - the bindable QProperty interval can't be changed to qint64 during Qt6's lifetime without the risk of breaking user code - adding a new bindable QProperty that is qint64/nanoseconds is an option, but it has the complication of what to do with the int interval; set it when setInterval(milliseconds) is used by using saturation arithmetic? and what about notifying observers of the changed interval? Thus the idea of creating a new stop-gap class, QChronoTimer, as a cleaner solution. Both classes use QTimerPrivate. During the lifetime of Qt6, QTimer's interval range is about 24 days, whereas QChronoTimer's interval range is about 292 years (duration_cast<years>nanoseconds::max()). Currently the plan is to fold QChronotTimer back into QTimer in Qt7. Mark all QPropertyS in the new class as FINAL since they aren't intended to be overridden; this offers a performance boost for QML[1]. [1] https://lists.qt-project.org/pipermail/development/2024-February/044977.html [ChangeLog][QtCore] Added QChronoTimer, which uses a std::chrono::nanoseconds intervals, as a replacement for QTimer. Fixes: QTBUG-113544 Change-Id: I71697f4a8b35452c6b5604b1322ee7f0b4453f04 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QMetaObject: revert adding QMetaObject::indexOfEnumerator(QBAV)Ahmad Samir2024-01-301-4/+0
| | | | | | | | | | | | | | | | This partially reverts 4ecbe42ff44ace881ed4962744e9cd6c8fa65dab . The discussion is still ongoing to decide whether the new overload should take a QBAV or QAnySV. See https://codereview.qt-project.org/c/qt/qtbase/+/514588 for the details. For the time being remove the new overload from the API so that this can be backported to 6.7 (while keeping both dev and 6.7 in sync to ease future backports). Pick-to: 6.7 Change-Id: I4a279653d1941faeafd95dde7a8c741009c00c72 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* invokeMethod: std::forward universal-ref argumentMårten Nordheim2024-01-201-1/+1
| | | | | | | | | Spotted in API review Pick-to: 6.7 Change-Id: I4ab660bb9955176f40b4123e775d65c17edbeeb8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Suppress clang-tidy mem leak warning on QMetaObject::invokeMethodThiago Macieira2023-12-141-0/+1
| | | | | | | | | | | | We don't leak, but clang-tidy is printing this warning. Possibly because it sees a new with no matched delete in the same context, ignoring the fact that the pointer was gifted to the called function. Fixes: QTBUG-119972 Pick-to: 6.7 6.6 6.5 Change-Id: I6e2677aad2ab45759db2fffd17a06c57c3a463ba Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMetaObject: add indexOfEnumerator(QBAV) overloadAhmad Samir2023-10-271-0/+6
| | | | | | | | | | | | | | | | | And remove the indexOfEnumerator(const char *) overload. Taking by view so that it works with string data that isn't necessarily null-terminated (e.g. a sliced() or chopped() view). QMetaObjectPrivate::indexOfEnumerator needs to be a member function because it usess a private QMetaEnum constructor (QMetaObjectPrivate is a friend of QMetaEnum). [ChangeLog][QtCore][QMetaObject] Added indexOfEnumerator(QByteArrayView) overload. And deprecated indexOfEnumerator(const char *) overload. Change-Id: Ie2f4f1a9af69373c19a5d7bd92499544e95e9289 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* invokeMethod: enable passing parameters to overload taking functorsMårten Nordheim2023-08-241-10/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | This was missing for a while, and there is nothing fundamentally missing for it to work. With the more recent work around slot objects and invokeMethod in general, it is a good time to add support for this. In this patch, when connecting to a functor, it automatically deduces the overload to call based on the arguments passed to invokeMethod. Sharing code with QObject::connect could be done, but they have a key difference that makes it harder: With signal emissions we throw away trailing arguments that are not used: i.e. `signal(int, int)` can be connected to `slot(int)` or `slot()`. With invokeMethod that's not a thing. So we will need a way to toggle that behavior during resolution. [ChangeLog][QtCore][QMetaObject] Added support for passing parameters to the overload of QMetaObject::invokeMethod that takes a functor. These new overloads must have the return-value passed through qReturnArg(). Change-Id: If4fcbb75515b19e72fab80115c109efa37e6626e Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make qReturnArg return a type templated with the return typeMårten Nordheim2023-08-241-8/+15
| | | | | | | | | | | | | This way we can make check verify that the passed-in pointer is correct at compile time. Doesn't do this in this patch because all current uses are in the string-based overloads, but we'll use it in a later patch which adds new invokeMethod overloads for the functor-based API. Change-Id: I30186adc9d0b67c7ca337deb35c2c34661e50261 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qobjectdefs.h - fix comment typoAxel Spoerl2023-08-171-1/+1
| | | | | | Pick-to: 6.6 Change-Id: I314c01156daaaf993ff0b80e049327d52e520382 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix QMetaObject::invokeMethod for free functions and std::bindVolker Hilsheimer2023-05-111-0/+2
| | | | | | | | | | | | | | | | | | | | Amends 3bf5b5f8944dd417530b09dd6f1cd568717c8cc1, after which free functions and std::bind could no longer be used as callables in QMetaMethod::invokeMethod. For free functions to work we need to decay to function pointers when choosing what type QtPrivate::Callable aliases. And std::bind has operator() overloads and the return type cannot be deduced. So simplify the definition of the ZeroArgFunctor - we know the function prototype if we know the return type. Add testcase for calling std::bind and free function, and remove the now unneeded helpers for functor argument and return type deduction. Change-Id: I54aac5cb6d660267e6b2f5ab05d583e8826cdf9a Reviewed-by: Zoltan Gera <zoltan.gera@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Rename QFunctorSlotObject to QCallableObjectVolker Hilsheimer2023-05-101-1/+1
| | | | | | | | | | | | | | After the recent changes we only have a single implementation of QSlotObjectBase, which can handle free functions, member functions, functors, and lambdas. Rename it to callable, and explicitly hide the static implementation function so that it doesn't become a symbol of static libraries using Qt. Also rename makeSlotObject to makeCallableObject, and polish coding style and comments in the qobjectdefs_impl header a bit. Change-Id: Id19107cedfe9c624f807cd8089beb80e9eb99f50 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QSlotObject helpers in functor-cases of QMetaObject::invokeVolker Hilsheimer2023-05-051-33/+10
| | | | | | | | | | | | | | | | | | | | Add helper that allows us to determine the argument list and return type of a functor. This triggers a compile time error if the functor has operator()() overloads (we only support zero-argument call operators, but there might be const/noexcept variations). Use that helper to declare a ZeroArgFunctor type which also declares a ReturnType and Arguments alias. Add a Callable alias that now combines FunctionPointer and ZeroArgFunctor into a single type that we can then use to merge the specializations of QMetaObject::invokeMethod. [ChangeLog][Potentially source-incompatible changes] Using a functor with several operator() overloads in QMetaObject::invokeMethod now causes a compile time error. Qt would previously ignore const and noexcept overloads and always call the mutable version on a copy of the functor. Change-Id: I3eb62c1128014b729575540deab615469290daeb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Simplify invokeMethod implementations using QSlotObject helpersVolker Hilsheimer2023-05-041-37/+11
| | | | | | | | | Remove duplication for overloads covering member function pointer or function pointer cases, as those are now covered by the new QtPrivate::makeSlotObject helper. Change-Id: Ife1e05416958e40a4759ca06cf7db185031b8a86 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Revert "Support move-only functors in invokeMethod and async APIs"Volker Hilsheimer2023-05-011-12/+12
| | | | | | | | | This reverts commit 9958edba41ac49097a54e0872c3c4934d2dd81f9, which incorrectly tested a move-only functor without actually moving the functor. Change-Id: I3707f9f8e5055102f7edfb3e1cb9750978356dd7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Support move-only functors in invokeMethod and async APIsVolker Hilsheimer2023-04-281-12/+12
| | | | | | | | | | | | | Move-only functors must never be passed by value, so fix the QFunctorSlotObject constructor accordingly. This then requires adjustments to the various QMetaMethod::invokeMethod overloads, as those must also perfectly forwad the functor type. Enable the previously failing test case for move-only functors. Change-Id: I9c544fd3ddbc5e1da3ca193236291a9f83d86211 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qobjectdefs.h: properly disable rvalue qReturnArg()Marc Mutz2023-03-021-1/+1
| | | | | | | | | | | | | | | | | | template <typename T> qReturnArg(T&&) is an unconstrained perfect forwarder, and will "win" for everything for which `T&` is not an equal match. e.g. a volatile T. Restrict the deleted overload to actual rvalues. We don't need to use `const volatile T&&`, because rvalues never bind to `T&`, we just need to get off using a universal reference, and adding const does that. As a drive-by, change the deleted overload's return type to void, to mimic std::as_const(), the prototype for rvalue-deleted function overloads. Pick-to: 6.5 Change-Id: If4fbc311677b993488859b2c4e226b94daed71fe Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qobjectdefs.h: optimize AreOldStyleArgsMarc Mutz2023-03-011-3/+3
| | | | | | | | | | Use a template alias instead of C++98-style inheritance. Saves one template instantiation. Pick-to: 6.5 Change-Id: I95ee9cf1e5eac1db5fc8e05cd95f5e745134214d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaObject: Fix version check for deprecated methodsFabian Kosmale2023-02-071-2/+2
| | | | | | | | | | We don't want them in Qt 7.0.0, either. As a drive-by, also guard the implementation with the same check. Pick-to: 6.5 Change-Id: I21b181e5563ebc2b247d6c5ad005bb76224f0daf Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* moc: Allow calling ctors on pre-allocated dataUlf Hermann2023-02-021-1/+2
| | | | | | | | | | | | When calling a ctor this way, an object is created in the memory pointed to by _a[0] using the other arguments for the ctor. This allows separate allocation and initialization of an object through the metaobject system. Fixes: QTBUG-108879 Change-Id: Ifb154373ee42faab281cfb62aa14334980ec6b7d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-211-7/+7
| | | | | | | | | | | | | | | | | | | | | | | To allow the user to customize the C++ code that QDoc sees, so as to be able to work-around some limitations on QDoc itself, QDoc defines two symbols: Q_QDOC and Q_CLANG_QDOC, both of which are "true" during an entire execution of QDoc. At a certain point in time, QDoc allowed the user the choice between a custom C++ parser and a Clang based one. The Q_QDOC symbol would always be defined while the Q_CLANG_QDOC symbol would be defined only when the Clang based parser was chosen. In more recent times, QDoc always uses a Clang based parser, such that both Q_CLANG_QDOC and Q_QDOC are always defined, making them equivalent. To avoid using different symbols, and the possible confusion and fragmentation that derives from it, all usages of Q_CLANG_QDOC are now replaced by the equivalent usages of Q_QDOC. Change-Id: I5810abb9ad1016a4c5bbea99acd03381b8514b3f Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Replace qExchange calls with std::exchangeFabian Kosmale2022-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | qExchange is one of the few remaining functionalities that have not been moved out of qglobal. Given that std::exchange exists in the standard, we can simply move to it everywhere... ...if it weren't for the fact that std::exchange is only constexpr in C++20, and only has its noexceptness specified in (most likely) C++23. Still, we want to move to the existing std functionality where possible, to allow the removal of qglobal includes in lieu of something more fine-grained in the future. So leave any constexpr calls[1] alone for now (and observe that none of our current usages cares about the conditional noexceptness), but replace everything else. [1] QScopedValueRollback' ctor and QExplicitlySharedDataPointerV2::take Task-number: QTBUG-99313 Change-Id: I599cb9846cf319c7ffd3457130938347a75aad25 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMetaObject/Doc: document the variadic invoke{,Method} and newInstanceThiago Macieira2022-09-011-1/+22
| | | | | Change-Id: Ic6547f8247454b47baa8fffd170dc646d4f73152 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
* QMetaObject: pass the QMetaTypes in variadic invoke/newInstanceThiago Macieira2022-09-011-19/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][Meta Object] QMetaMethod::invoke(), QMetaObject::invokeMethod(), and QMetaObject::newInstance() are no longer limited to 10 arguments. [ChangeLog][QtCore][Meta Object] The use of the Q_ARG macro is no longer necessary when using QMetaMethod::invoke(), QMetaObject::invokeMethod(), and QMetaObject::newInstance(). Types may now be passed directly. Similarly, Q_RETURN_ARG can be replaced by the free function qReturnArg(). [ChangeLog][Potentially Source-Incompatible Changes] QMetaMethod::invoke(), QMetaObject::invokeMethod(), and QMetaObject::newInstance() no longer support passing forward-declared types in the argument list (it was possible to pass them by const-ref). From Qt 6.5 onwards, all types in the argument list must be fully defined. [ChangeLog][Potentially Source-Incompatible Changes] Attempting to use the internal types QArgument, QReturnArgument, QGenericArgument, or QGenericReturnArgument directly with QMetaMethod::invoke(), QMetaObject::invokeMethod() or QMetaObject::newInstance() may fail to compile. Those are internal types that were never meant to be used directly and will be removed in Qt 7. If really necessary, ensure all arguments passed to those functions are directly using those classes and not mixed with Q_ARG and Q_RETURN_ARG. Implementations of bindings to other languages should contact the Qt development mailing list to discuss options. Change-Id: I36b24183fbd041179f2ffffd1701e3e8e47e0fba Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMetaObject: add a new, variadic invoke/invokeMethod/newInstanceThiago Macieira2022-08-301-5/+141
| | | | | | | | | | | | | | | | | [ChangeLog][QtCore][Meta Objects] The QMetaObject::invokeMethod() taking a method name by string, QMetaObject::newInstance(), and QMetaMethod::invoke() now support more than 10 arguments. [ChangeLog][QtCore][Meta Objects] The use of the Q_ARG and Q_RETURN_ARG macros is now optional with QMetaObject::invokeMethod(), QMetaObject::newInstance(), and QMetaMethod::invoke(): the type name will be obtained from the C++ type (the same as QMetaType). The function qReturnArg() can be used in place of the Q_RETURN_ARG macro. The macros are still useful in rare conditions where the type was typedef'ed from its original name. Change-Id: I36b24183fbd041179f2ffffd17022a2b48c7639b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* moc: fix const-init for WindowsThiago Macieira2022-06-281-1/+2
| | | | | | | | | | | | | | | | | | References to __declspec(dllimport) is not a constant expression on Windows, so we can't have a direct reference to a staticMetaObject. Commit 9b8493314dd77f3e96b353187816bb7ef4dedbb5 fixed the Q_OBJECT parent link (added in 5.14, kicked in for 6.0 with the ABI break), but commit 656d6f2a9b221dbd5adfc46262cb243e696d8d62 added links for Q_GADGETs too without taking the need for Windows DLLs into account. This change is a no-op everywhere but Windows. On Windows, since we store the pointer to the indirect getter function, now you may get non- null pointers from QMetaObject::superClass(). Pick-to: 6.4 Change-Id: I6d3880c7d99d4fc494c8fffd16fab51aa255106e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QMetaObject: Allow custom meta callsUlf Hermann2022-03-171-1/+2
| | | | | | | | | Add a new entry to the Call enum that can be used by dynamic meta objects to encode their own metaCall variations. Change-Id: I7890d11924ab99311b6f016ce97d2ab483c26d27 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* qobjectdefs.h: DRY the SIGNAL/SLOT macrosMarc Mutz2022-03-111-18/+21
| | | | | | | | | | | | | | | Factor common code into a separate macro to DRY. The immediate paractical consequence is that we now have a way to reliably get a const char[] from the SIGNAL or SLOT macros, e.g. for storing in a QOffsetStringArray, without causing compile errors in debug mode or running the danger of causing runtime initialization via qFlagLocation, which is of limited value in this circumstance, anyway, because qFlagLocation only stores the last two strings. Pick-to: 6.3 Change-Id: I67401858e94eedc1200fdd08e695fd56d10f8560 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtCore: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Introduce QMetaObject::metaTypeFabian Kosmale2021-03-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This function returns the metatype corresponding to the metaobject, or an invalid metatype for namespaces. This works as follows: First we increment the metaobject revision for new metaobjects. Metaobjects with older revisions are handled by doing a lookup by name. That fallback is also used for dynamic metaobjects (from QtDBUS and those created by QMetaObjectBuilder). For new metaobjects, we store the metatype in its metatype array, behind the property metatypes. This avoids any changes to the property and method metatype extraction logic: For properties, the metatype access does not change, as the new metatype is after their metatypes. For method metatypes, we already have an indirection layer (using offsets), so by adjusting those offsets by one, the same logic keeps working. To distinguish between namespaces and dynamic metaobjects, namespaces store the metatypeinterface pointer for void in the metatype array, whereas dynamic metaobjects store a nullptr. One nice additional benefit is that this simplifies the generator logic in moc, as the metatype array is now never empty. Task-number: QTBUG-92077 Change-Id: Id3f920f28553f12032a71a1a87dad29e5374dbe7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Doc: Fix various documentation issues for Qt CoreTopi Reinio2020-10-311-2/+2
| | | | | | | Task-number: QTBUG-86295 Change-Id: I3bf7d4b1533d4fc81114d353b19beaf4ea9b93b2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Make most of QMetaTypeInterface constexprUlf Hermann2020-10-181-1/+1
| | | | | | | | | | | | | | | | | | The only thing we need to modify at runtime is the typeId and that can be mutable. This way we can have a constexpr ctor for QMetaType which hopefully makes the importing and exporting of related symbols less fickle. On Windows we cannot make QMetaTypeForType constexpr as that leads to mysterious errors in other places. Until we figure out why that is, we just leave this class as non-constexpr. This reveals that qcoreapplication.h and qvariant.h are using QDebug without including it. We now get template instantiation errors. Include qdebug.h to avoid that. Change-Id: If1bf0437ada52459c59c6fa45bab3d22dfb0bc92 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Centralize the implementation of move assignment operatorsGiuseppe D'Angelo2020-10-031-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment we have two main strategies for dealing with move assignment in Qt: 1) move-and-swap, used by "containers" (in the broad sense): containers, but also smart pointers and similar classes that can hold user-defined types; 2) pure swap, used by containers that hold only memory (e.g. QString, QByteArray, ...) as well as most implicitly shared datatypes. Given the fact that a move assignment operator's code is just boilerplate (whether it's move-and-swap or pure swap), provide two _strictly internal_ macros to help write them, and apply the macros across corelib and gui, porting away from the hand-rolled implementations. The rule of thumb when porting to the new macros is: * Try to stick to the existing code behavior, unless broken * if changing, then follow this checklist: * if the class does not have a move constructor => pure swap (but consider ADDING a move constructor, if possible!) * if the class does have a move constructor, try to follow the criteria above, namely: * if the class holds only memory, pure swap; * if the class may hold anything else but memory (file handles, etc.), then move and swap. Noteworthy details: * some operators planned to be removed in Qt 6 were not ported; * as drive-by, some move constructors were simplified to be using qExchange(); others were outright broken and got fixed; * some contained some more interesting code and were not touched. Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Inline QMetaObject::cast(QObject *), as requested by ### Qt 6 commentEdward Welbourne2020-09-101-2/+3
| | | | | | Task-number: QTBUG-85700 Change-Id: I29405df37b82d34a92537e39a3863b5f6c998556 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Make bindings introspectable through mocLars Knoll2020-09-021-2/+1
| | | | | | | | | | | | | | | Add a new BINDABLE declaration to the Q_PROPERTY() macro that tells moc where to find the QBindable for the property. Add a QUntypedBindable base class to QBindable<T> that gives access to generic functionality and checks argument compatibility at runtime. QBindable<T> will still do static checking at compile time. Add QMetaProperty::isBindable() and QMetaProperty::bindable() to be able to dynamically access the binding functionality. Change-Id: Ic7b08ae2cde83fd43e627d813a886e1de01fa3dc Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Leave a comment about a usage of a restricted bool trickGiuseppe D'Angelo2020-08-231-0/+2
| | | | | | | | | | | | | | I'm pretty sure we want to keep supporting statements like bool ok = connect(~~~); that is, statements that do use copy initialization and not direct initialization. As such, QMetaObject::Connection has to keep using the restricted bool trick and cannot be ported over to explicit operator bool. Change-Id: I07a38f7c134686e67b5984aa93fe5cf3201561d7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Qt6: remove support for property flags being functionsLars Knoll2020-06-111-5/+0
| | | | | | | | | | | | | | | Property flags should be compile time booleans, not something to be determined at runtime. We've been using this to dynamically disable some properties in QWidget based classes dependent on the state of a different property, but this should better get implemented on top of our widgets. Change-Id: I6296e8761303ecdf24d9e842142e8596304c015d Reviewed-by: Simon Hausmann <hausmann@gmail.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QMetaMethod: clean up offset handlingLars Knoll2020-06-111-1/+1
| | | | | | | | | | | | Centralize the offset handling in one place and avoid lots of magic numbers in various places. Expose the number of ints per method in QMetaObjectPrivate as a constant, so that code in other places can access it via private API. Change-Id: I59790287a17ea47e6160ec65d9c8d0aaee748947 Reviewed-by: Simon Hausmann <hausmann@gmail.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Add support for exposing public QProperty members in the meta-object systemSimon Hausmann2020-03-181-1/+3
| | | | | | | | | | At the moment this makes the type as well as the setter/getter available through the meta-call as well as the ability to register observers and bindings. Only QProperty members that are annotated with Q_PROPERTY(type name) are made public through the meta-object. Change-Id: I16b98fd318122c722b85ce61e39975284e0c2404 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2020-02-261-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: examples/network/bearermonitor/CMakeLists.txt examples/network/CMakeLists.txt src/corelib/tools/qlinkedlist.h src/sql/kernel/qsqldriver_p.h src/sql/kernel/qsqlresult_p.h src/widgets/kernel/qwidget.cpp src/widgets/kernel/qwidget_p.h tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp tests/auto/tools/moc/allmocs_baseline_in.json Change-Id: I21a3c34570ae79ea9d30107fae71759d7eac17d9
| * Replace usage of std::result_of with decltypeMårten Nordheim2020-02-211-1/+1
| | | | | | | | | | | | | | | | It's slated for removal in c++20 Fixes: QTBUG-82240 Change-Id: I7b35c151413b131ca49b2c09b6382efc3fc8ccb6 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* | MetaObject: store the QMetaType of the propertiesOlivier Goffart2020-02-251-0/+5
| | | | | | | | | | Change-Id: I563e7232b70e94de4184f2c23a581319313dcf5c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Use the QByteArray::DataPointer typedef instead of QByteArrayDataLars Knoll2019-12-081-1/+0
| | | | | | | | | | | | | | | | The goal here is to move things over to QArrayDataPointer. This prepares for it. Change-Id: I32f54a47594274799600c618f7341c200ceaa306 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Inline the size and data pointers in QByteArrayThiago Macieira2019-12-081-1/+1
| | | | | | | | | | Change-Id: I82feeb2c9bd2900f421fc0c8d78698b1e83db043 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Change representation of string data in the meta objectLars Knoll2019-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Don't store our string data as QByteArrayLiterals anymore, but revert back to simply storing them as an array of char* and offsets into that array. This is required to be able to inline size and begin into QByteArray itself. Once that change is done, we can then avoid creating copies of the string data again. Change-Id: I362a54581caefdb1b3da4a7ab922d37e2e63dc02 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Use Q_NAMESPACE for the Qt namespace, and remove the old moc hack to support itOlivier Goffart2019-12-061-184/+1
| | | | | | | | | | | | | | | | | | | | Since I can't #include qobjectdefs from qnamespace because of circular dependency, move the Qt macro in the qtmetamacros.h header. Deprecate QObject::staticQtMetaObject since now one can just use Qt::staticMetaObject Change-Id: I11982aa17c2afa2067486b113f8052672f3695eb Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* | Add support for slots to receive the raw void ** arguments arrayLars Knoll2019-10-071-0/+4
|/ | | | | | | | | | | This is currently being used by dbus und our state machine framework, and supported by hand editing moc generated code. Get rid of that hack, and instead add support to moc to forward the raw arguments array to the slot. Change-Id: I0e36626f91eb01041464e6d931dc1d4660de91d2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Qt6: Fix uninitialized meta objects on WindowsThiago Macieira2019-07-161-4/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Windows has a problem relating to cross-DLL variable relocations: they are not supported. Since QMetaObject's link to the parent class is done via a pointer, every QMetaObject in a DLL or in the EXE that derives from a class from another DLL (such as QObject) will be dynamically initialized. This commit changes the meta object pointers in QMetaObject::d from raw pointers to a wrapper class SuperData, which is almost entirely source- compatible with the pointer itself. On all systems except for Windows with Qt 6, it's binary compatible with the current implementation. But for Windows with Qt 6, this commit will store both the raw pointer and a pointer to a function that returns the QMetaObject, with one of them non-null only. For all meta objects constructed by moc, we store the function pointer, which allows the staticMetaObject to be statically intialized. For dynamic meta objects (QMetaObjectBuilder, QtDBus, QtQml, ActiveQt), we'll store the actual raw pointer. [ChangeLog][QtCore][QMetaObject] Some internal members of the QMetaObject class have changed types. Those members are not public API and thus should not cause source incompatibilities. The macro QT_NO_DATA_RELOCATION existed in Qt 4 but was called Q_NO_DATA_RELOCATION and only applied to Symbian. It was removed in commit 24a72c4efa929648d3afd95b3c269a95ecf46e57 ("qglobal: Remove symbian specific features"). Task-number: QTBUG-38876 Fixes: QTBUG-69963 Change-Id: Id92f4a61915b49ddaee6fffd14ae1cf615525e92 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Introduce Q_NAMESPACE_EXPORTGiuseppe D'Angelo2019-06-281-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A recurring problem with the Q_NAMESPACE macro is that it declares an object (staticMetaObject) in the surrounding namespace. That object lacks any export/import qualification to make it usable with shared libraries. Introduce therefore another macro to work around this issue, allowing the user to prefix the object with an exporting macro, f.i. like this: Q_NAMESPACE_EXPORT(Q_CORE_EXPORT) The old macro can simply then be rewritten in terms of this new one, supplying an empty export macro. Note that NOT passing an argument to a macro expecting one is well defined behavior in C99 -- the macro will expand an empty token. Of course, MSVC doesn't like this and emits warnings. As a workaround, use a variadic macro. [ChangeLog][QtCore] Added the new Q_NAMESPACE_EXPORT macro. It can be used just like Q_NAMESPACE to add meta-object information to a namespace; however it also supports exporting of such information from shared libraries. [ChangeLog][Potentially Source-Incompatible Changes] Prefixing Q_NAMESPACE with an export macro may no longer work. Use the new Q_NAMESPACE_EXPORT macro for that use case. Fixes: QTBUG-68014 Change-Id: Ib044a555ace1f77ae8e0244d824ec473550f3d8e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: BogDan Vatra <bogdan@kdab.com>
* Merge remote-tracking branch 'origin/5.13' into devLiang Qi2019-06-141-0/+4
|\ | | | | | | | | | | | | | | | | | | Conflicts: qmake/generators/makefile.cpp qmake/generators/unix/unixmake2.cpp src/corelib/thread/qthread_unix.cpp tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp Change-Id: I1df0d4ba20685de7f9300bf07458c13376493408
| * doc: Fix tr() documentation issueMartin Smith2019-06-131-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | The declaration of tr() in the Q_OBJECT macro interferes with the tr() declaration in the QObject class. This update fixes that bug by resetting QT_TR_FUNCTIONS to be empty and by ensuring that the tr() declaration in class QObject is seen by clang when qdoc is running. Change-Id: If55339fc417f3eee1a1e1ce3df75a18af443d630 Task-number: QTBUG-75864 Reviewed-by: Paul Wicking <paul.wicking@qt.io>