summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject.h
Commit message (Collapse)AuthorAgeFilesLines
* QObject: add check for Q_OBJECT macro to findChild(ren)Thiago Macieira2024-04-031-0/+6
| | | | | | | | | | | | | | | | | We can't fix the underlying reported problem, but we can warn that the user has made a mistake. [ChangeLog][QtCore][QObject] The class template parameter passed to QObject::findChild() or findChildren() is now required to have the Q_OBJECT macro. Forgetting to add it could result in finding children of the nearest ancestor class that has the macro. Pick-to: 6.7 Fixes: QTBUG-105023 Change-Id: I5f663c2f9f4149af84fefffd17c008f027241b56 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Timers: add Qt::TimerId enum classAhmad Samir2024-03-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Which will be used to represent timer IDs. Thanks to Marc for the idea to use "a strongly typed int". QTimer got a new id() method that returns Qt::TimerId (can't overload timerId()). Various classes in qtbase have a member named timerId(), but a new method is needed anyway in QTimer so id() it is (this is the reason QChronoTimer only has id() and no timerId()). Besides timer.timerId() has an extra "timer". This commit fixes the inconsistency between QObject using `0` timer id to indicate "failed to start", while QTimer::timerId() returned `-1` to indicate "timer is inactive". QTimer::id(), being a new method and all, now returns Qt::TimerId::Invalid, which has value `0`, so that the values match between the two classes. Extend the unittests to ensure QTimer::timerId()'s behavior is preserved. [ChangeLog][Core][QObject] Added Qt::TimerId enum class, that is used to represent timer IDs. Change-Id: I0e8564c1461884106d8a797cc980a669035d480a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSingleShotTimer: use nanoseconds precisionAhmad Samir2024-02-231-0/+6
| | | | | | | | | | | | | | This is a step towards making QChronoTimer have nanoseconds precision. Not changing QTimer::singleShot() methods to take nanoseconds; QTimer uses milliseconds for the most part, having the static singleShot() methods take nanoseconds would be a bit surprising? [ChangeLog][Core][QObject] Added startTimer() nanoseconds overload and removed the milliseconds overload. This change is backwards compatible. Change-Id: I69e79c8feb6354846c6d3be57dc529af7abd1313 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QObject: Let moveToThread return succcess stateChristian Ehrlicher2024-01-241-0/+3
| | | | | | | | | | | | | | | Add bool QObjectPrivate::moveToThread() which returns the success state of the attempt to move the object to the new thread. For Qt7 the public signature of QObject::moveToThread() should be changed to directly return this value. [ChangeLog][QtCore][QObject] QObject::moveToThread() now returns a boolean success state. Pick-to: 6.7 Change-Id: I8441c8155a76b804b473ab9c45c2be6840ef1677 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QObject: assert connection type isn't UniqueConnection for lambdasAhmad Samir2023-12-221-1/+6
| | | | | | | | | | | | | | | An assert is harder to miss than a warning, which makes it more likely to get fixed. Thanks to Mårten Nordheim for the idea. Add the assert in inline code so that users compiling their code in debug mode (or with -DQT_FORCE_ASSERTS) can hit the assert even when built agaist a release build of Qt (not everyone compile their code with a debug build of Qt). Thanks to Giuseppe D'Angelo for the idea. Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-115125 Change-Id: I2935d32ea5a2c288d7a836abbae66ac53cb5ab2f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QObject: re-add the nameless qt_qFindChildren_helper to restore BCThiago Macieira2023-12-211-0/+2
| | | | | | | | | | | | | | | | | | Amends e608bc019232f6956c4520be1a6103a1845c6991 by adding the implementation of this method whose implementation got accidentally removed (because it became unused). It's added in removed_api.cpp because, as the commit said, the cost for creating an empty QAnyStringView is practically nil. It's not zero on Windows, because the replacement function has five parameters, so the last (the options) is passed on the stack. But that is not enough of a justification to keep separate functions. Pick-to: 6.7 Fixes: QTBUG-120309 Change-Id: I6e2677aad2ab45759db2fffd17a29b4ec7728426 Reviewed-by: Rym Bouabid <rym.bouabid@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QObject: allow calling findChild() without a nameRym Bouabid2023-11-221-1/+7
| | | | | | | | | | | Add an overload of findChild() without a name argument to be able to call the function with options value only. [ChangeLog][QtCore][QObject] Added findChild() overload taking no name. Task-number: QTBUG-103986 Change-Id: Id06b6041408fcf4cc1eeba975afce03f3a28f858 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QObject: port findChild/ren() to QAnyStringViewRym Bouabid2023-11-221-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Change the object's name type in QObject::findChild/ren() to QAnyStringView, because they are only used for comparison against objectName property. qt_qFindChild{,ren}_helper() functions taking an objectname as QString have to stay in the ABI as they were exported in inline methods before Qt 6.7. Unlike QString, constructing a null QAnyStringView doesn't involve any code-size overhead. So, get rid of the split in qt_qFindChildren_helper that was introduced for QString. Remove unneeded qt_qFindChildren_with_name helper function and qt_qFindChildren_helper overload without a name. findChildren(options) method used to call qt_qFindChildren_helper overload. Instead, call findChildren overload with name argument and pass QAnyStringView{} as the object name. [ChangeLog][QtCore][QObject] Ported QObject::findChild/ren() and their helper functions to QAnyStringView. Task-number: QTBUG-103986 Change-Id: I68bda0e581f984ae48b7581ad86cc1b95008c1b0 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* qobject_cast: add a couple of static_assertsGiuseppe D'Angelo2023-09-201-0/+6
| | | | | | | | | ... for better error reporting. Change-Id: I11afdef41f729b4357b743a3238c1f055a1d35d3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Implement QSignalBlocker::dismiss()Axel Spoerl2023-08-311-0/+6
| | | | | | | | | ...to set m_o to nullptr and prevent an existing QSignalBlocker from touching the QObject, which it was created for. Add documentation and implement an autotest. Change-Id: Ic18e80af5a57df1928f9d36aa0ab7ad79b6525fd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Allow QObjects to opt in to receiving ParentAboutToChange/ParentChangeTor Arne Vestbø2023-08-301-1/+2
| | | | | | | | | | | | | | | | | | | QWidget already handles this, but it might be useful for non-Widget object hierarchies as well, such as in Qt Quick. The flag is opt in, and as QWidget already handles these events by itself (without checking any flags), we assert that we don't end up in this code path, instead of enabling it for QWidget. The latter would mean refactoring the QWidget code, with possible regressions. Docs and header comments have been updated to reflect that this event is not widget specific. (This is an issue with other events as well, that are documented to say "widget", since they came from a time when there was only QWidget, but nowadays apply to e.g. QWindow as well. That's something for another fix though). Change-Id: Ib71962131d6011c17dcce8c01bd8adcdaa58d798 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QObject: replace _q_reregisterTimers with a lambdaAhmad Samir2023-07-311-1/+0
| | | | | | | | | | | | | | | - Pass the QList by value, no heap allocation and no plain new/delete - A lambda means that there isn't runtime string-based lookup to find the member method in QObjectPrivate The code is only a couple of lines and used in a single place, so might as well move the code from _q_reregisterTimers to the local lambda. Modify tst_moc to account for the numer of methods in QObjectPrivate changing. The test had hardcoded numbers. Change-Id: I07906fc7138b8e601e4695f8d2de1b5fdd88449c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove all class-level [[nodiscard]] from the code-baseMarc Mutz2023-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A class-level [[nodiscard]] used to be the only way to get a waring for code such as QMutexLocker(&mutex); with original C++17 means. This was because a few of our compilers would warn about the presence of [[nodiscard]] on ctors, which is really the semantics we want: we don't want to prevent users from passing QMutexLocker out of functions and users of those functions from ignoring the return value, if they so choose. That should be the choice of the author of the function returning such types, not ours. So QUIP-0019 makes class-level [[nodiscard]] conditional on proper rationale in the user docs (or the commit message in case of private API). Since none of the existing uses really strikes this author as particularly convincing, remove them all. All these classes have gotten Q_NODISCARD_CTOR on all their ctors, so we continue to provide the same true positive warnings, minus the false positives when returning from functions, at least on the majority of compilers (and it's not as if all compilers interpreted a class-level [[nodiscard]] as a trigger to warn on the initial example of this commit message). Task-number: QTBUG-104164 Pick-to: 6.6 Change-Id: I163356486e7c80f9d69bf67023010a88233fe662 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QObject: introduce QT_NO_CONTEXTLESS_CONNECTGiuseppe D'Angelo2023-06-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | The 3-arguments overload of connect() is error-prone / easy to misuse: * it's easy to e.g. connect to a lambda, and capture local state in the lambda. By not passing a receiver/context, the connection won't get disconnected if the local state gets destroyed (effectively, it creates a "dangling connection"); * in a multithread scenario, one may not realize that the connection is forced to be direct. If the signal is emitted in another thread than the one establishing the connection¹, then the functor will be invoked in that other thread. (Not that "the thread establishing the connection" has ever mattered, but again, this API is error-prone.) Add a macro that allows users to disable the overload in their project. I'm not going for deprecation because there's simply too much code around that uses it. [ChangeLog][QtCore][QObject] Added the QT_NO_CONTEXTLESS_CONNECT macro. Defining the macro before including any Qt header will disable the overload of QObject::connect that does not take a receiver/context argument. Change-Id: I86af1029c1a211ea365f417aae9038d3fcacadfd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Pacify MSVC compiler incorrectly warning about unused variableVolker Hilsheimer2023-06-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Under some circumstances, MSVC seems to complain about SlotArgumentCount being unused qobject.h(210): warning C4189: 'SlotArgumentCount': local variable is initialized but not referenced note: see reference to function template instantiation 'QMetaObject::Connection QObject::connect<void(__cdecl QAction::* )(bool), main::<lambda_1>>(const QAction *,Func1, const QtPrivate::ContextTypeForFunctor<main::<lambda_1>,void>::ContextType *, Func2 &&,Qt::ConnectionType)' being compiled This is nonsense, as SlotArgumentCount is used in the next line, to construct the list of signal arguments, but the workaround to declare the variable as [[maybe_unused]] is trivial. Add a connect statement to the test case that creates such a connection. This does not produce any warning with or without the attribute (and if it did, the build would fail for CI configuratinos setting -Werror). Pick-to: 6.6 Fixes: QTBUG-114781 Change-Id: I4ee6f7d57c2836ef3dd9741d037d48181af2cdec Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QSignalBlocker: plaster with [[nodiscard]]Marc Mutz2023-06-131-1/+4
| | | | | | | | | | It's a RAII class, and RAII classes should be marked [[nodiscard]] at the class as well as the ctor level. Pick-to: 6.6 Task-number: QTBUG-104164 Change-Id: I77260dc00d51d62ed1064e13f566d04e88d28ef9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QObject: add setProperty() overload taking rvalue QVariantMarc Mutz2023-05-311-0/+15
| | | | | | | | | | | | | | | | Instead of duplicating the long-ish implementation, simply pass the variant as pointers to const and mutable, and implement a runtime version of std::forward. [ChangeLog][QtCore][QObject] Added setProperty() overload taking an rvalue QVariant. Fixes: QTBUG-113281 Task-number: QTBUG-112762 Change-Id: Ifdc8f626ad5db138073474c3bd95ec7308c4396b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* 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>
* Merge QSlotObject and QFunctorSlotObject, and use helpers to deduplicateVolker Hilsheimer2023-05-021-91/+25
| | | | | | | | | | | Now we can use QFunctorSlotObject for any kind of callable - free function, functor, or PMF. This allows us to fold the various overloads of QObject::connect together, removing duplicate code and error handling logic. Change-Id: I8842f5ddd29e86be07a422647a8fc1678fd534b1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Remove QStaticSlotObject, use QFunctorSlotObject insteadVolker Hilsheimer2023-05-021-10/+10
| | | | | | | | The two slot object types are identical as long as we use a universal reference and perfect forwarding in the respective connect overloads. Change-Id: I999d71707dd045a17156e3bfecd371da7979beb1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Give QtPrivate::List a size value, simplify QFunctorSlotObjectVolker Hilsheimer2023-05-021-1/+1
| | | | | | | | | | | | The meta-programming list can easily know its size, so no need to pass both a list and its size as template parameters to QFunctorSlotObject, which simplifies existing code and is a step towards merging QFunctorSlotObject and QSlotObject. Also, remove the unused List_Select helper. Change-Id: I8ec6a0b707eab531ec06aba4e82223f242e53f2f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QObject: implement startTimer(int) in terms of startTimer(chrono)Ahmad Samir2023-03-111-5/+1
| | | | | | | | | | I.e. use chrono first, this means the API isn't limited by the size of int, but by the size of whatever chrono::milliseconds uses (typically int64_t), and chrono units are much more readable as well. Task-number: QTBUG-110059 Change-Id: Ie7f2d90864782361a89866693011803be6f8545e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-211-6/+6
| | | | | | | | | | | | | | | | | | | | | | | 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>
* Remove preprocessor conditionals for chrono includeKonrad Kujawa2022-09-161-5/+1
| | | | | | | | | __has_include(<chrono>) is always true, because C++11 chrono include is required since 6.0. Pick-to: 6.4 6.3 6.2 Change-Id: I50cb92571bf4f1f86e2f3f2b5f486dd3c3f30f4a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* 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>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-1/+1
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QObject: port setObjectName() to QAnyStringViewMarc Mutz2022-03-151-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... while keeping the QString overload for users that pass actual QStrings (e.g. QStringLiteral). However, QString and QAnyStringView cannot be overloaded (they're ambiguous for most arguments), so we need to make one of them a Q_WEAK_OVERLOAD. Normally, we'd make the new function weak and keep the old function as-is, but, here, that would be beside the point, because all callers would continue to resolve to the QString overload, and nothing would call the QAnyStringView one. So we really want the old function to be the Q_WEAK_OVERLOAD, so that the QString overload is only selected when actual QStrings are passed. That means we need to leave the old function in a compat build (compiled in, but not visible in the public header). Since Q_WEAK_OVERLOADs cannot be (easily) exported (they're templates), make it call a private function (which can be, and is, exported). Reviewers may questions whether one can overload setObjectName() and template <typename = void> setObjectName() The answer is that we can, because templates mangle differently from normal functions. We can even call the template function (with explicit template arguments), as seen in removed_api.cpp. This adapts the interface of the function to how most users use it: They pass QLatin1String or just const char[]. Only very few passed QStringLiteral, which, ignoring that fact that it produces a ton of code for the temporary QString's destructor that's never executed, would have been, and continues to be, the optimal way of passing data, modulo plugin bugs (QTBUG-51602, QTBUG-49061). [ChangeLog][QtCore][QObject] Added setObjectName() overload taking QAnyStringView. Fixes: QTBUG-101393 Change-Id: I1243545614754b4978d4c8641460980b6b293c1a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QProperty: fix threading issuesFabian Kosmale2022-03-101-1/+1
| | | | | | | | | | | | | | | | | | | | QObject's cache the binding status pointer to avoid TLS lookups. However, when an object is moved to a different thread, we need to update the cached pointer (as the original thread might stop and thus no longer exist, and to correctly allow setting up bindings in the object's thread). Fix this by also storing the binding status in QThreadPrivate and updating the object's binding status when moved. This does only work when the thread is already running, though. If it is not running, we instead treat the QThreadPrivate's status pointer as a pointer to a vector of pending objects. Once the QThread has been started, we check if there are pending objects, and update them at this point. Pick-to: 6.2 6.3 Fixes: QTBUG-101177 Change-Id: I0490bbbdc1a17cb5f85044ad6eb2e1a8c759d4b7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Core: Remove 'properties' featureKai Köhne2022-02-141-2/+0
| | | | | | | | | | | | | Even QtCore alone cannot be built without the properties feature since Qt 5.5. While fixing this is easy, other modules like dbus, networking are also using QObject::property() and friends liberally. All in all I doubt that anybody will miss the feature (otherwise it would have been fixed in the last decade). Change-Id: Iaf3cc20bda54ee2ff3b809fac8fa82b94ecc88c0 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix qobject_cast on partially destroyed QWidget/QWindowGiuseppe D'Angelo2022-01-051-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QWidget and QWindow use bits in QObjectPrivate to provide for a couple of shortcuts -- one in qobject_cast, and another in the isWidgetType() / isWindowType() functions in QObject. These can be optimized by simply looking at the bits, without actually doing more expensive runtime casts. These bits were set on construction, but not unset on destruction. The result was for instance that destroying a QWidget would report that the object was still a QWidget when ~QObject was reached. Fix this 1) by setting the bits only when QWidget / QWindow constructors start; 2) by resetting the bits once ~QWidget / ~QWindow are completed. Technically speaking this is not 100% correct in the presence of data members, but luckily those classes don't have any. Amend an existing test for QWidget (whose comment said exactly the opposite of what the test actually did) and add a test for QWindow. Some other code was wrongly relying on isWidgetType() returning true for destroyed QWidgets; amend it as needed. [ChangeLog][QtCore][QObject] Using qobject_cast on partially constructed or destroyed QWidget/QWindow instances now yields correct results. Similarly, using the convenience isWidgetType() / isWindowType() functions now correctly return false on such instances. Before, qobject_cast (and the convenience functions) would erroneously report that a given object was a QWidget (resp. QWindow) even during that object's construction (before QObject's constructor had completed) or destruction (after QWidget's (resp. QWindow's) destructors had been completed). This was semantically wrong and inconsistent with other ways of gathering runtime type information regarding such an object (e.g. dynamic_cast, obj->metaObject()->className() and so on). Pick-to: 6.3 Change-Id: Ic45a887951755a9d1a3b838590f1e9f2c4ae6e92 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Add QObject::isQuickItemType() for convenienceYuhang Zhao2021-12-231-1/+3
| | | | | Change-Id: Ibde4e919ba028117336974eb7a804aa11c1ee086 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QObject: don't #include qproperty.hMarc Mutz2021-11-231-2/+2
| | | | | | | | | | | | | | | | | | | | | The qobject.h header needs QBindingStorage in-size and QBindable in-name-only. The former was moved to its own header in a previous commit, which we include now, while the latter can just be forward-declared. This allows dropping the qproperty.h include from qobject.h. [ChangeLog][Potentially Source-Incompatible Changes] The qobject.h header no longer implicitly includes qproperty.h. If your code depends on the transitive include, explicitly include <QProperty> where needed. Task-number: QTBUG-97601 Pick-to: 6.2 Change-Id: I8d6320f5978e20dfc394d2b1e49f626b99529c37 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Return a plain QMetaObject* from toDynamicMetaObject()Ulf Hermann2021-10-071-0/+3
| | | | | | | | | | | | | | | | | | | The only place where we use it, we swiftly cast it to QMetaObject* anyway. Generating an object with virtual methods, only to then cast to its non-virtual base type is dangerous. Also, if we are required to return a QAbstractDynamicMetaObject from a method of QDynamicMetaObjectData, we cannot implement QDynamicMetaObjectData without also implementing QAbstractDynamicMetaObject. This indirectly forces us to copy metaobjects around as we cannot wrap an existing metaobject into a QDynamicMetaObjectData subclass. Copying metaobjects around makes QMetaObject::inherits() unusable because inherits() assumes identity is determined by identity of the pointer. Change-Id: Icbe697efa6fd66649eef3c91260c95cda62e3c90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Q_DECLARE_INTERFACE: rework to use more inline functionsThiago Macieira2021-09-141-7/+19
| | | | | | | | | | That way, we can add the NOLINTNEXTLINE comment to suppress clang-tidy, which otherwise flags all usage of const_cast in C++ code. Change-Id: Ie72b0dd0fbe84d2caae0fffd16a247b96d223772 Reviewed-by: Rui Oliveira Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Q_DECLARE_INTERFACE: delete unspecialized qobject_interface_iid()Thiago Macieira2021-09-071-3/+2
| | | | | | | | Instead of making it return a non-useful nullptr. Change-Id: Ie72b0dd0fbe84d2caae0fffd16a245cce5ea65f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Q_DECLARE_INTERFACE: add missing const to const qobject_castThiago Macieira2021-09-071-1/+1
| | | | | | | | | | | | | | [ChangeLog][Potantially Source-Incompatible Changes] The macro Q_DECLARE_INTERFACE used to cast away the constness of the QObject parameter. That is now fixed in this release, but may cause failure to build source code that depended on this incorrect behavior. If fixing the const correctness in your code is not an option, insert an explicit const_cast<IFace *> of the object prior to the qobject_cast call. Change-Id: Ie72b0dd0fbe84d2caae0fffd16a246a36f0c088f Reviewed-by: Rui Oliveira Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QObject: optimize the common case of findChildren(QString())Marc Mutz2021-07-131-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Outside tests, all in-tree callers of QObject::findChildren() pass no name to match, and in my experience that is also true for the vast majority of out-of-tree users. Avoid the temporary QString creation in the caller and the repeated QString::isNull() checks in the implementation by overloading findChildren() without a name argument and checking for name.isNull() only once, forking off into separate helper functions. Adjust in-tree callers that used an explicit `QString()` argument in order to pass options, which goes to show that `name` should never have been the first argument of findChilden() in the first place, even though I appreciate the symmetry with findChild() (the use-cases of which, however, are radically different). Change a `findChildren().size() == 0` call found while scanning for findChildren() calls to `!findChild()` as a drive-by. Modernize loops in the various qt_qFindChild{,ren}_helper() overloads to match how the new code looks. [ChangeLog][QtCore][QObject] Added findChildren() overload taking no name (thus optimizing this common case). Change-Id: Ifc56e5438023d079b40c67f11ae274a3e128ad5e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QObject: make new-style-connects SFINAE-friendlyMarc Mutz2021-07-121-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SFINAE out the new-style connect() overloads for const char* functions. Before, we detected the problem in the body of connect(), by failing the static_assert for signal/slot argument compatibility, but that's too late. We don't want to select that overload at all, because we want that decltype(QObject::connect(QAction*, &QAction::triggered, QObject*, SLOT(something())) SFINAEs instead of returning QMetaObject::Connect, because then all the classes that provide convenience new-style connect syntax by wrapping the QObject::connect() call can just use that decltype() to accept anything that will succeed in the wrapped connect() call instead of manually trying (and failing) to provide proper overloads themselves. [ChangeLog][QtCore][Potentially Source-Incompatible Changes] QObject::connect(sender, pointer-to-member, [receiver, ], SLOT(~~~)) is now SFINAEd out instead of triggering a static_assert(). That means it is now possible to use Expression SFINAE (decltype(QObject::connect(<sender>, <signal>, std::declval<Args>()...) to properly wrap new-style QObject::connect() calls with a single wrapper function, greatly simplifying the implementation, incl. passing Qt::ConnectionType arguments. For more information on how to use this in your own code, see the sources of QWidget::addAction(). Change-Id: I4052a49eacd63a432a9648a667adc435744a633d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Consistent indentation for BINDABLE propertiesAndreas Buhr2021-06-241-1/+1
| | | | | | | | | Triggered by API review in Gerrit patch 355960. Task-number: QTBUG-94407 Pick-to: 6.2 Change-Id: I7cafc1cc9d4b929040b53c6bf92c91d73c3b39f2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QObject: port to new property systemIvan Solovev2021-04-211-1/+3
| | | | | | | | | | | | | | | Extended QObjectPrivate::ExtraData to store a pointer to its parent, and reimplemented qGetBindingStorage() function for QObjectPrivate::ExtraData. This allows to use Q_OBJECT_COMPAT_PROPERTY macro for a property, stored in QObjectPrivate::ExtraData and solves all the problems with calling a custom setter. Task-number: QTBUG-85520 Change-Id: I40e01c29430846359ef9160fa1ae97c702be9a18 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Inline access to the QBindingStorageLars Knoll2020-11-301-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | And inline the fast checks inside the methods in QBindingStorage. This allows QObjectBindableProperty and friends to inline all the fast checks and almost completely eliminates the overhead for property accesses when no bindings are being used. Read and write times of QObject based properties when no bindings are being used: Read Write Old style property: 3.8ns 7.3ns QObjectBindableProperty (no notification): 4.5ns 4.3ns QObjectBindableProperty (with signal): 4.5ns 7.6ns QObjectBindableProperty (inline accessors): 3.2ns 3.4ns Numbers without this patch: Old style property: 3.8ns 7.9ns QObjectBindableProperty (no notification): 7.2ns 7.7ns QObjectBindableProperty (with signal): 7.2ns 16.0ns QObjectBindableProperty (inline accessors): 6.3ns 6.7ns Change-Id: Ifd1fa3a489c3be8b1468c0b88af547aac397f412 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 98c82fb445acf45cc4c4bc86a5adda43358127bf) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Whitespace cleanup in corelib/kernelAllan Sandfeld Jensen2020-10-241-9/+14
| | | | | Change-Id: If061ef0af5ced4384e20a82afcea3712fa7e45d7 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add a QBindingStorage classLars Knoll2020-09-021-0/+11
| | | | | | | | | | | | | | | | | | | QBindingStorage is a class that can store a set of binding objects for the properties of a QObject. This will get used to reduce the memory overhead of the property system when adding bindable properties to QObject based classes. The binding storage has a pointer to the TLS entry containing the currently evaluating binding. Like that we avoid repeated TLS lookups and reduce the overhead of the property system to one pointer lookup and one compare for the case that properties aren't being used. Each QObject now owns one binding storage object, that can be used to store binding data for properties that members of the QObject. Change-Id: I27427c03c2ba281f072e074be96147bdbcaac246 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QObject/Q_OBJECT: remove deprecated old APIEdward Welbourne2020-08-141-19/+2
| | | | | | | Since 5.0, trUtf8(), qFindChild() Change-Id: I7bc0d125f92faebf24a422c1aac528a3f4687434 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove non-Qt6 compile time switches from QtCoreAllan Sandfeld Jensen2020-07-241-5/+0
| | | | | | | | We already manage to compile without this code, and none of it are full classes or separate functions suitable for qt5compat. Change-Id: I47facac7ec621cfc4b0b26214b7de37897443519 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-15/+15
| | | | | | | | | | | | | | | | | There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove QRegExp based functionality from QObjectLars Knoll2020-04-151-28/+0
| | | | | | | QRegExp is going away for Qt6. Change-Id: I04d6331379dc769394b160d976eb9f21fe649a22 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2019-12-111-2/+2
|\ | | | | | | | | | | | | Conflicts: tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp Change-Id: I6b82507bf9a80a374c40393e72f4843f1557de89
| * Don't wrap feature detection macros with QT_HAS_FOO() variantsTor Arne Vestbø2019-12-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using wrappers for these macros is problematic when for example passing the -frewrite-includes flag to preprocess sources before shipping off to distcc or Icecream. It will also start producing warnings when compilers implement http://eel.is/c++draft/cpp.cond#7.sentence-2. See for example https://reviews.llvm.org/D49091 Both https://clang.llvm.org/docs/LanguageExtensions.html and the SD-6 document at https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations recommend defining '__has_foo(x) 0' as a fallback for compilers without the macros, so that's what we go for. Change-Id: I0298cd3b4a6ff6618821e34642a5ddd6728be767 Reviewed-by: Alex Richardson <arichardson.kde@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Use Q_NAMESPACE for the Qt namespace, and remove the old moc hack to support itOlivier Goffart2019-12-061-6/+0
| | | | | | | | | | | | | | | | | | | | 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>