summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QMetaType: Track whether type is QML list typeFabian Kosmale2020-11-231-0/+1
| | | | | | | | | This information is required in the QML engine to handle list properties (instances of QQmlListproperty<T> and list<T> types from QML). Pick-to: 6.0.0 6.0 Change-Id: I1e30572f1c91f58b290cb9b4b07433af99a1db6f Reviewed-by: Ulf Hermann <ulf.hermann@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 some QMetaType members constexpr and inlineLars Knoll2020-10-231-30/+5
| | | | | | | | | Since QMetaType::fromType() is constexpr, it makes sense to also make some of it's members constexpr. Change-Id: Ia2d63a904abb680ed63c1f88cb68f1d0309d029c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Rename the QMetaType::MovableType flag to RelocatableTypeLars Knoll2020-10-231-1/+2
| | | | | | | Keep this in sync with the changes we have done in QTypeInfo. Change-Id: Iaacb0f3cc5c46d3486084a1f6eca480a233d5e1a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix documentation for hidden friend operatorsVolker Hilsheimer2020-10-231-4/+2
| | | | | | | | At least for qdoc, hidden friends are class members. Change-Id: I6eaa21565937cd49c0905ee47b8b82b0c1765bc1 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Make most of QMetaTypeInterface constexprUlf Hermann2020-10-181-7/+7
| | | | | | | | | | | | | | | | | | 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>
* QMetaType: Avoid combination of extern and declspec(__dllexport) on MSVCUlf Hermann2020-10-121-1/+10
| | | | | | | | | MSVC does strange things with this, and it actually tells us so via a warning. We can, however, attach the dllexport to the definition, rather than the declaration of the symbols in order to resolve the problem. Change-Id: I9971e13afc6d8840c49ec20d21820a72c5407200 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Another round of replacing 0 with nullptrAllan Sandfeld Jensen2020-10-071-2/+2
| | | | | | | | | This time based on grepping to also include documentation, tests and examples previously missed by the automatic tool. Change-Id: Ied1703f4bcc470fbc275f759ed5b7c588a5c4e9f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Fix some qdoc warnings in QMetaType and QVariantVolker Hilsheimer2020-09-241-20/+15
| | | | | | | | Document new enum values, remove documentation for implicit members, fix parameters, and tie documentation to function definitions. Change-Id: I5f32d45be8709e5f614d099ddf21252e23e144f8 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Fix some qdoc warnings: function parameter namesVolker Hilsheimer2020-09-221-3/+3
| | | | | | | In QTextDocument and QTextFormat, standardize language a bit. Change-Id: I7c81ecc7a32e36ec32214e6b5386a2827cfcbc3f Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Remove default ctor for QIterableUlf Hermann2020-09-221-2/+2
| | | | | | | MSVC has strange problems with it and we don't actually need it. Change-Id: I2c443946d52d475208800f310b5f910da165c99b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaType: Allow registration of mutable views and register iterablesUlf Hermann2020-09-191-45/+297
| | | | | | | | | | | | | | | In order to modify a container through an iterable, we need the original container to be mutable. The iterable, then, is not a conversion of the container, but rather a view on the container. The concept may be extended to other types. In order to facilitate this, provide a set of methods in QMetaType and QVariant similar to the convert family. The new methods are non-const and expect the original value to stay available during the life time of the view. Change-Id: I363621033f7fc600edcea2acb786820ccba49c86 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Extend QSequentialIterable and add QAssociativeIterableUlf Hermann2020-09-191-26/+39
| | | | | | | | | And add mutable iterators. This requires some refactoring of the existing iterators. Task-number: QTBUG-81716 Change-Id: I61b3a3e8c0df5fd449679257a29d9f0c3d19c4f0 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QVariant: guard usage of fromType.metaObject()Richard Moe Gustavsen2020-09-111-1/+1
| | | | | | | | | | | | | | | | This patch amends 19874d6a63. That patch caused a crash to occur when running the auto test tst_QQuickApplicationWindow::attachedProperties(). The crash can be traced back to QMetaType trying to access fromType.metaObject(), which is null. This patch will add a guard to ensure that we don't try to call a function on an object that is null. Fixes: QTBUG-86517 Change-Id: Idafd154a7b6a43e16126038fc5f9b30d7871f0d0 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix a number of MSVC integer conversion warningsFriedemann Kleint2020-09-101-1/+1
| | | | | | | | Mostly related to qstrlen(). Change-Id: I69e2052c83766e4fc466ed398d0d0eac011a77ec Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
* Reimplement QSequentialIterable using QMetaSequenceUlf Hermann2020-09-031-13/+8
| | | | | Change-Id: Ie721a5f0caa697c4bf15a81f3762cf79d3c54f5a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QVariant: Fix conversion codeFabian Kosmale2020-09-021-2/+11
| | | | | | Fixes: QTBUG-86330 Change-Id: Ib89dcf1195e0081b4c4e2845f90c52c612e5911a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Make the canConvertMetaObject method safeLars Knoll2020-08-241-3/+4
| | | | | | | | | | This triggered a crash in QtQml, where an manually created metattype interface set the PointerToQObject flag to true while not providing a metaobject. Change-Id: I206fb9655058a1e8a2d04e44186b05db33358338 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Pass QMetaType by valueLars Knoll2020-08-241-5/+5
| | | | | | | | Now that QMetaType is not refcounted anymore, we can and should pass it by value. Change-Id: I848db65070713762f548ca949097c27783aacad4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean up int based convert() APILars Knoll2020-08-241-40/+52
| | | | | | | Pass QMetaType instances instead. Change-Id: I07366cea566fdebf5bb793aa8087f8109216ec0c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Return a qsizetype from QMetaType::sizeOf()/alignOf()Lars Knoll2020-08-241-2/+2
| | | | | | | Object sizes in Qt 6 should use qsizetype. Change-Id: I76ceb5faf361d7f6be88d88c772358ad6d701d54 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Deprecate the static int based API in QMetaTypeLars Knoll2020-08-241-136/+38
| | | | | | | | | | | | | And remove one of the type id to name mapping that still existed in QMetaType. QMetaTypeInterface can provide that, so there's no need to have a second copy of the data. qMetaTypeTypeInternal() can still map all the names of all builtin types to ids. That functionality is for now still required by moc and can't be removed yet. Change-Id: Ib4f8e9c71e1e7d99d52da9e44477c9a1f1805e57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Remove refcounting of QMetaTypeInterfaceLars Knoll2020-08-241-23/+8
| | | | | | | | | It's only used for dynamic types in DBUS and QML, where we control things good enough to be able to handle the lifetime of those interfaces there. Change-Id: Ia7f8970d17a85b195db85fcdc2d8f1febd8753f4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove an unused enum value and document another oneLars Knoll2020-08-241-1/+1
| | | | | Change-Id: If9fed4f20242d789c1251b8798d7378d2d6911a6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cleanup qvariant_cast<>Lars Knoll2020-08-241-0/+9
| | | | | | | | | | Move the last functionality it had (casting between QObject derived types) over to QMetaType. Now qvariant_cast<> is nothing but a wrapper around QMetaType::convert(). Change-Id: Iab02b6b97c141d64052823646e18227d1eb403dd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move conversions to and from *Iterables into QMetaTypeLars Knoll2020-08-241-9/+189
| | | | | | | | Those were not yet supported by QMetaType. Change-Id: I9f85476049f200e35939ac58ef7e8b4e7cbe0b77 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Implement QMetaType::canConvert() and use it in QVariantLars Knoll2020-08-241-0/+142
| | | | | | | | | | | | | | | | | | | | Use the fact that we return the conversion function as a lambda to find out reliably whether a conversion between two types can be done. This requires some minor adjustments to our tests: * Nothing can convert to an unknown type and vice versa * Adjust results to the fact that we don't convert from char to QString anymore (where the old method was incorrect) * QStringList->QString requires some adjustments, as we only convert if the string list has exactly one element. For now we return true in canConvert(), but the conversion behavior in this case is something we should rethink, as it is very surprising. Change-Id: I3f5f87ee9cb99d690f5a7d13b13d6a6313d8038e Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Get rid of the old QVariant conversion codepathLars Knoll2020-08-241-1/+17
| | | | | | | All conversions do now happen through QMetaType::convert(). Change-Id: I70f7a883262087768acccf8361d34c0490ff2b43 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move QJsonValue and QCborValue conversions to QMetaTypeLars Knoll2020-08-241-0/+127
| | | | | Change-Id: Id4796e0913c0c5b0abce0ea27bed0f7b41bc0cca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Finish porting number conversions to QMetaTypeLars Knoll2020-08-241-11/+29
| | | | | Change-Id: I2861c6fb5f8192a627ffb41f1455c703849cf945 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move enum conversions over into QMetaTypeLars Knoll2020-08-241-1/+144
| | | | | | | | Take the opportunity to properly handle the underlying type (size and signed vs unsigned). Change-Id: I0cb8cf40acac6de03c24ed3fe570db68268952c8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Implement integral conversions in QMetaTypeLars Knoll2020-08-241-1/+108
| | | | | Change-Id: Ib2617d37b80bb45818dcd093744cfe5a37a74606 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Start porting conversions over from QVariant to QMetaTypeLars Knoll2020-08-241-0/+387
| | | | | | | | | | This will ensure full symmetry in what QVariant and QMetaType support. With this done, QVariant will become simply a container that can hold any QMetaType with fully symmetric functionality between both. Change-Id: I796d4368a2bc0f08cf4f70f4465ed6a0e07bdd76 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Add a metatype helper class for Qt CoreLars Knoll2020-08-241-15/+28
| | | | | | | | | This helps get better symmetry with the other modules, and to unify the code paths for both conversion and retrieving the interface for static types. Change-Id: Icbd20de2563f36e3de20d826323acd057734abfb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QMetaTypeModuleHelper as the interface to do type conversionsLars Knoll2020-08-241-0/+4
| | | | | | | | | | | | | | Move the type conversions from QVariant::Helper to QMetaType. Only do this for Qt Gui in a first step. This makes it possible to completely remove the Handler struct in QVariant, and now allows QMetaType to also convert Gui types. Moving the conversion of Core types into QMetaType will require further work. Change-Id: I061f789deca1b595d92bb29227eb54b8e71a3ee3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Clean up the converter function handlingLars Knoll2020-08-241-10/+10
| | | | | | | | Use std::function to register the converter functions instead of our own handrolled interface. Change-Id: Ifc1d1d383d21ee8d4239dbc3970c1f31bf0f4037 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Get rid of the unused meta type switcherLars Knoll2020-08-241-1/+0
| | | | | Change-Id: I8771feb68227bf69643b66314284c645cccdec6f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Generate less code when creating QMetaTypeInterfacesLars Knoll2020-08-241-6/+18
| | | | | | | | | There is no need to generate wrapper functions for equals, lessThan or debugStream for pointer types, as those can easily be handled by a few lines of code in QMetaType itself. Change-Id: If79b3bc3a629249c1d17c9e592202f08b59f80ef Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Refactor Q*IterableLars Knoll2020-08-241-5/+0
| | | | | | | | | | | | Refactor the methods retrieving data in Q*Iterable so that we don't return pointers with unclear ownership. Instead, copy the data into a out pointer provided by the caller. This also means there is no need for the metatype flags anymore and we can remove those. Change-Id: I517de23a8ccfd608585ca00403aca0df2955f14b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Small doc fixLars Knoll2020-08-241-3/+1
| | | | | | | | Change-Id: I349f68c4b86558aba5db4e8fbe5d876447baaeb3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Automatically register data/debug stream operations in QMetaTypeLars Knoll2020-08-241-274/+97
| | | | | | | | | | | | | | | | | | | | | | And remove the old manual registration code for those operators. Add some special handling for long/ulong, as these types could be streamed as a QVariant so far, but are not directly streamable through QDataStream. [ChangeLog][QtCore][QMetaType] The QMetaType::registerStreamOperators() and QMetaType::registerDebugStreamOperator() methods have been removed. The streaming operators for a type are now automatically registered together with the type registration. This implies that the operators should be visible wherever the type is visible and being used. [ChangeLog][Behavior Incompatible Changes] Because the QDataStream and QDebug serialization operators are automatically registered with QMetaType, the declarations of those functions must be present at any point where the type is used with QMetaType and QVariant. Change-Id: I4a0732651b20319af4a8397ff90b848ca4580d99 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Expose QMetaTypeInterface::alignof in QMetaTypeFabian Kosmale2020-07-311-2/+23
| | | | | | | | | | We already have the information in the QMetaTypeInterface, and provide functions to access sizeof. Adding alignof support seems natural, and should make it easier to handle over-aligned types. This should also be helpful in QVariant. Change-Id: I166be76f4b7d2d2e524a3a1e513bd2f361e887c1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix a number of qdoc warnings related to deprecationFriedemann Kleint2020-07-241-21/+1
| | | | | | | Remove obsolete documentation. Change-Id: Iaf4b6f9852a883dea0f256c5c89e74f6ebbe85f3 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Automatically register comparison operators in QMetaTypeFabian Kosmale2020-07-081-69/+98
| | | | | | | | | | | | | | | | | This removes the fully manual registration of comparison operators in QMetaType and replaces it with an automatic registration through Q_DECLARE_METATYPE(). [ChangeLog][QMetaType] The QMetaType::registerComparator() and QMetaType::registerEqualsComparator() have been removed. Q_DECLARE_METATYPE() now automatically registers any operator==() and/or operator<() for a type visible where it is used on that type, as part of declaring its meta-type. Change-Id: I3df451b652b735c093533838bf32f3cc785439f8 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use QList instead of QVector in corelib implementationJarek Kobus2020-06-291-3/+3
| | | | | | | | Omitting state machine and docs for now. Task-number: QTBUG-84469 Change-Id: Ibfa5e7035515773461f6cdbff35299315ef65737 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-4/+4
| | | | | | | | | | | | | | | | | 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>
* Warn about constructing QMetaTypes/QVariants with invalid type idsLars Knoll2020-06-161-0/+2
| | | | | | | | | | | Warn about using an invalid type id in all cases. So far, only some constructors of QVariant would warn. Move the warning over to the place where we map a typeid to a QMetaTypeInterface to catch all cases. Change-Id: I4cd48a2b5d6c597dbf2afbeae9b811cd0819b768 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Make the default constructor of QMetaType constexprLars Knoll2020-06-161-3/+0
| | | | | | | And inline the copy constructor forwarding to another one. Change-Id: I3c4f76f7b14edd84f512ef0687416b20940e333a Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
* Remove QRegExp from QVariantLars Knoll2020-05-141-2/+0
| | | | | | | | | | | | | | | | Add an operator QVariant() to QRegExp to keep things at source compatible as possible. Add a hack to QVariant::load/save() to recognize the old typeid for QRegExp and stream them correctly as long as the streaming operators for QRegExp are registered. Also move the datastream test for QRegExp to tst_qregexp, and adjust it to the qvariant changes. Change-Id: I120b38a7541b43ec07a21b17f7f35c55f071eb75 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMetaType: Add namespace where necessaryFabian Kosmale2020-04-021-1/+1
| | | | | Change-Id: I973522331bec057bcf0ddb72e46776249dff8aa8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>