summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QObject: fix installEventFilterOrder() test flakinessJarek Kobus2024-02-041-45/+40
| | | | | | | | | | Don't rely on timer precision and use int counter instead. Amends 1fe88bf4cd919d4b5cadb4be2cf0193525c54673 Pick-to: 6.7 6.6 6.5 6.2 5.15 Change-Id: I057b4dd51014784ec9b244301b43583f3de6ddd1 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* QObject: add unittest to check the order of eventFilter() callsAhmad Samir2024-02-011-0/+75
| | | | | | | | | | | | | | | | | installEventFilter() prepends new objects to the eventList, so that events that are posted while processing events are left to the next round of event processing. This is a baseline test to check that subsequent commits preserve the current behavior. QCOMPARE_GT is available since Qt6.4, so make the check backportable to older releases too. Pick-to: 6.7 6.6 6.5 6.2 5.15 Task-number: QTBUG-120779 Change-Id: I5ed5e9c2917a9be62de4af19c3b72889399b4fe6 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
* QObject: Let moveToThread return succcess stateChristian Ehrlicher2024-01-241-3/+5
| | | | | | | | | | | | | | | 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/+36
| | | | | | | | | | | | | | | 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: allow calling findChild() without a nameRym Bouabid2023-11-221-0/+19
| | | | | | | | | | | 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-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Extend QTestPrivate property tests - actual implementation [2/2]Ivan Solovev2023-11-011-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch provides the actual implementation to detect binding loops in property setters. These test will help to catch all the existing binding loops that were introduced when migrating to new bindable properties. The logic of the new tests is taken from tst_QObject::objectNameBinding(), but generalized to be applicable to all bindable properties. The original code from tst_QObject can now be removed. The patch effectively reverts f791570b86ce4a0da45bb6e617701a48ee8189b7 because a lambda returning a nullptr now means that the binding loop test should be skipped, which is not a good default behavior. Now when all the existing bindable properties are fixed, it's fine to give a compilation error when adding new tests, if the class is not default-constructible. Task-number: QTBUG-116345 Pick-to: 6.6 6.5 Change-Id: I059d444d4bb023c050a22e5b1974565e4f581b5c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Allow QObjects to opt in to receiving ParentAboutToChange/ParentChangeTor Arne Vestbø2023-08-301-0/+73
| | | | | | | | | | | | | | | | | | | 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: Do not register an observer when writing objectName propertyUlf Hermann2023-08-211-0/+10
| | | | | | | | | Observers should only be registered when _reading_ the property. Otherwise we get binding loops. Pick-to: 6.6 6.5 Change-Id: I974f6ea444fa7a5d333ed79eea6f34e3d757d169 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* 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>
* Silence warning from unused variable in QObject testVolker Hilsheimer2023-05-251-1/+5
| | | | | | | | It's not needed, but makes the point for having a mutable lambda in the first place. Change-Id: I483862d6aee90bb62d4b5363c56a80bb05e14df7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSlotObjectBase: move the `which` parameter to the 4th positionThiago Macieira2023-05-111-0/+4
| | | | | | | | | | | | | | | | | | | This places the first through third parameters on the exact positions that they will be used to perform the operations in the switch, saving the compiler from generating a few instructions to move data around. All ABIs Qt supports that pass any function parameters in registers at all pass at least 4. We keep the return type as void (instead of returning bool, for the Compare case) so the compiler can apply tail-call optimizations for those two typical cases. PMF case: https://gcc.godbolt.org/z/9oP5boKfj Function case: https://gcc.godbolt.org/z/e9vEzd5dj Functor case: https://gcc.godbolt.org/z/s8Ejjra7P Change-Id: I3e3bfef633af4130a03afffd175d3e3009c56323 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Rename QFunctorSlotObject to QCallableObjectVolker Hilsheimer2023-05-101-3/+3
| | | | | | | | | | | | | | 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-0/+24
| | | | | | | | | | | | | | | | | | | | 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>
* QSlotObject helpers: add testcoverage for std::functionVolker Hilsheimer2023-05-051-1/+10
| | | | | Change-Id: I503c627c77eaab7d2e3456f23b55fdfcdc94c0ea Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Pass functor through as references until storedVolker Hilsheimer2023-05-031-2/+0
| | | | | | | | | | | | | | Amends 642f799fc6c36c88834a7e2a10904816a962c2cb to avoid unnecessary copies in between the calls to the QFunctorSlotObject construcotr. We can't use a univeral reference in the QFunctorSlotObject constructor as the call is not deduced. So provide two overloads for lvalue and rvalue references instead. The compile check in the test now no longer fails as we delay the storage until one level later, but that's acceptable. Change-Id: Ide95b4a73c70f6f47698dd1e95138aa5d48ee95d Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Small improvements to QObject unit testVolker Hilsheimer2023-05-021-10/+12
| | | | | | | | Remove duplicate test and outdated comment about move-only functors, and include return value in move-only functor test. Change-Id: I58dffe0ccf3ec12e7e05e2c9588303da4a7e75ff Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix test for move-only functor objectsVolker Hilsheimer2023-05-011-6/+63
| | | | | | | | | | | | | | Amend 3c6e9dcc623c9d7281a81174bb3a696e030f30a7 by making sure that we explicitly move move-only functors into the slot object in the respective tests, and that failing to do so doesn't compile. Also add test coverage for mutable lambdas, which work as they do with connected functors: the connection stores a copy, and calls don't modify the original functor. Change-Id: I637e6f407133e2f8f72109b3fe5369a11d19da93 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Revert "Support move-only functors in invokeMethod and async APIs"Volker Hilsheimer2023-05-011-4/+7
| | | | | | | | | 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>
* Add a helper for better error messages when functor is incompatibleVolker Hilsheimer2023-04-281-8/+2
| | | | | | | | | | | | Amends 207aae5560aa2865ec55ddb9ecbb50048060c0c0 to make it easy to create human-friendly error messages. Since the functor-accepting member functions are not removed from the API, the first compile error will be that there is no suitable overload of the makeSlotObject helper, which. With the assert helper, the first error message is easier to understand. Change-Id: I4878ec35a44ddfa5dc9d9e358d81c3fd40389c0c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Support move-only functors in invokeMethod and async APIsVolker Hilsheimer2023-04-281-7/+4
| | | | | | | | | | | | | 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>
* Support free functions and const functors as callbacksVolker Hilsheimer2023-04-281-0/+148
| | | | | | | | | | | | | | | | | | Amend 207aae5560aa2865ec55ddb9ecbb50048060c0c0, as code checker complained that we std::move'd a potential lvalue. This warning was valid if the public API did not accept the functor parameter by value. Fix this by consistently std::forward'ing the parameters through the call stack, and add a compile-time test. Writing that test revealed that the helper API didn't work with free functions, so fix that as well. It also revealed that QFunctorSlotObject couldn't work with a const functor, which is also fixed by this change. We cannot support move-only functors with that change, as it requires a change to QFunctorSlotObject that breaks the QMetaObject test. Change-Id: Iafd747baf4cb0213ecedb391ed46b4595388182b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make it possible to use QObjectPrivate::connect in private codeVolker Hilsheimer2023-03-101-2/+12
| | | | | | | | | | | | | | | | | | | | In most QObjectPrivate-subclasses, the Q_DECLARE_PUBLIC macro is used in the private segment of the class declaration. In that case, the q_ptr becomes a private member of the private class, and then the QObjectPrivate::connect function can no longer be used, as it needs to access the d_ptr. Fix this by declaring QObjectPrivate, and the static-assert-helper, as friends of the class using the Q_DECLARE_PUBLIC macro. Adapt the QObject test by moving the Q_DECLARE_PUBLIC macro into the private section of the test-private, and add a compile test. Pick-to: 6.5 6.5.0 Change-Id: Ifc04be3b305221e138b1e08bb3a3838d871f4fcb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QObject: Handle pointers to incomplete types in auto-connectionsFabian Kosmale2023-02-141-0/+37
| | | | | | | | | | | | | | | | | | The code for the QMetaMethod queuedConnectionTypes overload relied on QMetaMethod::parameterMetaType and QMetaType::flags() to detect whether we're dealing with a pointer (and then use the VoidStar metatype instead). However, if the type was incomplete when the slot was defined, and the type was not registered when connect was called, we would not find a metatype for the argument. However, in that case we might still be able to handle the method, by checking whether the type name of the arguments ends with a "*". This patch does that, fixing a regression from 5.15. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-108537 Change-Id: I54cc48a3343444480ab9094fe1ebaaa5aa75cee0 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* tst_qobject: port away from deprecated methodsIvan Solovev2022-08-301-27/+17
| | | | | | | | | | | | | | | | | | | | | | The patch includes the following replacements: * QMetaType::type("name") -> QMetaType::fromType<Type>().id() * QMetaProperty::type() -> QMetaProperty::typeId() * QVariant::Type -> QMetaType::Type * qRegisterMetaType<T>("name") -> qResigeterMetaType<T>() * The static QMetaType::{load,save} methods are replaced with non-static versions * Replace QCOMPARE(property.type(), QVariant::UserType) with QCOMPARE_GT(property.typeId(), QMetaType::User), because the deprecated type() method was treating each custom type (id >= QVariant::UserType) as QVariant::UserType, while the typeId() method simply returns the actual id. As a drive-by: remove unneeded QMetaType registration tests as we have tst_QMetaType to check it. Task-number: QTBUG-104858 Change-Id: Ia08e002efdf07ff83366a5193164dba96a956f9a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Don't access QObjectPrivate::declarativeData unguardedVolker Hilsheimer2022-08-201-0/+77
| | | | | | | | | | | | | | | | | | | | | The QObjectPrivate::declarativeData member is stored in a union with currentChildBeingDeleted. The QObject destructor always sets the currentChildBeingDeleted member of the union. It also sets the isDeletingChildren bool, which is the only way to find out which union member we can safely access. While the QObject destructor is deleting children and isDeletingChildren is set, we must not access the declarativeData member of the union. Add a test case that initializes the function pointers for the declarative handlers and constructs a situation where an object emits a signal while it is destroying children. Fixes: QTBUG-105286 Pick-to: 6.4 6.3 6.3.2 6.2 5.15 Change-Id: Iea5ba2f7843b6926a8d157be166e6044d98d6c02 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMetaType: disable conversion from smart pointer<const QObject>Giuseppe D'Angelo2022-05-211-0/+17
| | | | | | | | | | | | | | | | | | | | | QMetaType can register a converter from a smart pointer class to QObject *. The code tries to do so even if the smart pointer is actually holding a pointer to a _const_ QObject (e.g. shared_ptr<const QObject>), causing a compile error: ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1208:32: error: invalid conversion from ‘const QObject*’ to ‘QObject*’ [-fpermissive] 1208 | return p.operator->(); | ~~~~~~~~~~~~^~ | | | const QObject* Disable the conversion if indeed the source is const qualified. Change-Id: I9e9bc5992f74131e5cfd6ece9b83d4f26d370e92 Fixes: QTBUG-103741 Pick-to: 6.2 6.3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Use SPDX license identifiersLucie Gérard2022-05-161-29/+4
| | | | | | | | | | | | | 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>
* Remove remnants of the old Intel C++ compilerThiago Macieira2022-05-111-1/+1
| | | | | | | | | | | | | We don't support it any more. I don't think it has ever properly compiled Qt 6 (and it's no longer working for me against GCC 12's libstdc++ headers). If you report a bug against it, Intel support's first question is if you can try instead the new Clang/LLVM-based oneAPI C++ compiler. So we support only that one, which identifies itself as Q_CC_CLANG. Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16eb57a092c8439e Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QObject: add another couple of tests for broken connect()Giuseppe D'Angelo2022-03-171-0/+11
| | | | | | | | | Connecting to a non-signal should fail, but apparently it doesn't on Windows+MSVC under certain conditions. Task-number: QTBUG-101761 Change-Id: I3e014660e4e5b287242e32307f677bb22ab10a39 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QObject: give some TLC to dumpRecursive()Marc Mutz2022-03-161-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In no particular order: - use the variable field width feature of QString::asprintf() to generate the indentation implicitly, instead of fill()ing a QByteArray with the desired number of spaces - just default-construct 'flags', don't assign an empty string - use qUtf16Printable() to avoid funneling UTF-16 data through 8-bit encodings - use a C++11 ranged for instead of a counted loop - remove a pointless isEmpty() guard (the loop won't execute when the children().isEmpty()) - avoid copying object->children() (returns by cref, so it's also ok to stuff it directly into the ranged for loop). Add a test. Pick-to: 6.3 Change-Id: Ie7314713cb48de7e890cdee0760c0361dd24fd18 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix clang-cl build of tst_qobjectAllan Sandfeld Jensen2022-02-021-1/+1
| | | | | | | | Not MSVC, but pretends to be. Pick-to: 6.3 6.2 Change-Id: I5c201dd917e79a22d6ef15715bf1d3a7010d123e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QObject: Q_ASSERT the object type before calling a PMFThiago Macieira2021-11-271-2/+69
| | | | | | | | | | | | | | | | | | | | | | | | The old-syle signal-slot syntax had the advantage of not delivering signals to slots in derived classes after that derived class's destructor had finished running (because we called via the virtual qt_metacall). The new syntax made no checks, so a conversion from the old to the new syntax may introduce crashes or other data corruptions at runtime if the destructor had completed. This commit introduces a Q_ASSERT to print the class name that the object is not any more. Since this is in inline code, this should get enabled for users' debug modes and does not therefore depend on Qt being built in debug mode. It required some Private classes to be adapted to the new form, by exposing the public q_func() in the public: part. Pick-to: 6.2 Fixes: QTBUG-33908 Change-Id: Iccb47e5527544b6fbd75fffd16b874cdc08c1f3e Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Include qproperty.h where neededMarc Mutz2021-11-041-0/+1
| | | | | | | Don't rely on transitive include from qobject.h, which will go away. Change-Id: I99dd97ff4fb1d0632d040daab0bffa2d7b85d3ae Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Re-enable QT_NO_NARROWING_CONVERSIONS_IN_CONNECT for QtGiuseppe D'Angelo2021-10-131-0/+5
| | | | | | | | | | This define used to be set for the entirety of the Qt build but was lost during the qmake->CMake transition. Re-enable it. Change-Id: Idc4cb6ada485158559485b60f62f76439550b255 Pick-to: 6.2 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Compile autotests for IntegrityTatiana Borisova2021-09-201-4/+13
| | | | | | | | | - process environment/DNS are OFF for INTEGRITY Task-number: QTBUG-96176 Pick-to: 6.2 Change-Id: I189a97f88c96a428586c31a66b8d250e04482900 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Q_DECLARE_INTERFACE: delete unspecialized qobject_interface_iid()Thiago Macieira2021-09-071-2/+0
| | | | | | | | 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>
* QObject::connect(): fail to connect to a functor if UniqueConnection is passedGiuseppe D'Angelo2021-08-271-2/+3
| | | | | | | | | | | | | | | | | | | | | The connect() documentation makes it clear that UniqueConnection does not work with free functions / function objects and the like; only with actual PMFs. Rather than silently *ignoring* the flag, be vocal about its presence by warning, and make the connection fail (as the user has passed an illegal argument). [ChangeLog][QtCore][QObject] QObject::connect() now will refuse to connect a signal to a free function / function object if UniqueConnection is passed. Note that UniqueConnection has never worked for such connections -- the flag was simply ignored, and they were established multiple times. Now, the flag is not ignored and results in a connection failure (as well as a runtime warning by Qt). Change-Id: I6509667018c74f9bd24910cde0a1b16c5f84f064 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QPrivateSlotBase: add empty base class optimizationMarc Mutz2021-07-291-1/+1
| | | | | | | | | | | | | | | There are few slots whose lambdas are empty; most will at least capture [this]. But there are a few in Qt examples that do, e.g. []{ qApp->quit(); }. Logging is also an example. So go the extra mile and optimize for empty functors by inheriting from them as opposed to storing them in a member variable. Change-Id: I3904f10db5ebe904ba889d29c08569edd804df3b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QObject: optimize the common case of findChildren(QString())Marc Mutz2021-07-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: port to new property systemIvan Solovev2021-04-211-1/+10
| | | | | | | | | | | | | | | 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>
* tst_qobject: enable some tests for narrowingGiuseppe D'Angelo2021-03-301-3/+7
| | | | | | | | | | Compilers are catching up, so some #if 0 codepaths can now be conditionally enabled. Change-Id: Ia9e87a096bc2ae4789ab390a9170d9c1eb9690d6 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* tst_qobject: fix the detection for GCCGiuseppe D'Angelo2021-03-261-4/+14
| | | | | | | | | | | | | Q_CC_GNU is defined on compilers that masquerade as GCC (Clang, ICC), so using it to work around GCC-specific bugs is wrong. Introduce a local define for _only_ GCC and use it in place of Q_CC_GNU. Drive by: version-fence a test we now know it's been fixed upstream, and correct the link to the corresponding bug report. Pick-to: 5.15 6.0 6.1 Change-Id: I9059d6e6bf86157aca71590ac22afb1a1c114313 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QObject: remove QAbstractDeclarativeData::parentChangedFabian Kosmale2021-03-111-37/+0
| | | | | | | | The code in qtdeclarative did not do anything at all anymore. Change-Id: Idd97145cb74aeb4f43dfce2f282a765e90945073 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Add new special QObjectPrivate::{connect, disconnect} for QMLAndrei Golubev2021-01-181-0/+28
| | | | | | | | | | | | | | | | Original QML-specific connection mechanism ignores the receiver argument and uses sender as receiver. This causes uncontrollable memory growth in certain cases as connections on receiver persist even after receiver is destroyed New connect() with receiver parameter uses underlying API correctly, disconnect is provided for the symmetry (not sure it's really needed) Task-number: QTBUG-86368 Pick-to: 5.15 6.0 Change-Id: I4580d75b617cb2c4dfb971a4dfb8e943e325572b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace QtTest headers with QTestDavid Skoland2020-12-221-1/+4
| | | | | | | | | | | Complete search and replace of QtTest and QtTest/QtTest with QTest, as QtTest includes the whole module. Replace all such instances with correct header includes. See Jira task for more discussion. Fixes: QTBUG-88831 Change-Id: I981cfae18a1cabcabcabee376016b086d9d01f44 Pick-to: 6.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QMetaProperty::typeName: use name from metatypeFabian Kosmale2020-11-301-3/+3
| | | | | | | | | | | | | | | Except for types marked as unresolved, we're doing it anyway - the only difference is that now we skip looking up the metatype by typeid. [ChangeLog][QMetaProperty][Important Behavior Change] QMetaProperty::typeName returns now always the same name as name() of the corresponding metatype. This can cause a change for enum properties which were not fully-qualified. Change-Id: I1f57743948b7262ac06095d3bbc838d620f6e481 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Revert "QObject: simplify part of connection logic"Fabian Kosmale2020-10-271-0/+20
| | | | | | | | | | | | | | | This reverts commit 1918c689d78b0f6a718343e7ebceb387acc32a97. The template gets always instantiated in QObjectPrivate::connect, even if the connection types is not Qt::(Blocking)QueuedConnection. For non-queued connections we however support using incomplete types in connect. The only way to fix this would be to make the connection type a template parameter of QObjectPrivate::connect (or at lesat pass some compile time constant indicating "blocking"-ness) along, so that we can use if constexpr instead of if. As all involved classes are private, we can postpone investigating this solution to 6.1 Change-Id: Ieffaf015f8e60ca6ac6f85eb9e2756e480060b4f Reviewed-by: Lars Knoll <lars.knoll@qt.io>