Both the object and the listmodel may be deleted during the life time of
ModelObject. Don't crash when that happens.
Also, fix QV4QPointer to actually name the type of the pointer it
stores. Apparently this is the first time we add a QV4QPointer of
something that's not a plain QObject.
Pick-to: 5.15
Task-number: QTBUG-118024
Change-Id: I208d8749bcd67970f7bfbe569eed7a472f909508
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 90c55e859e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit aa253878fe)
(cherry picked from commit f7182e0124)
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
(cherry picked from commit ca5bd206d49fafb813c52570a89006ed1967b17c)
This is the simplest way to prevent the garbage collector from
destroying the object while at the same time allowing a manual
destruction.
Task-number: QTBUG-95895
Task-number: QTBUG-96167
Fixes: QTBUG-91390
Change-Id: Ic3f3146bc555991068ce3367971e050f745d235d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 718f3469f6)
Previously each test would include and build sources from the shared
folder. Now we make those sources a library, build it once, then have
each test link to it instead.
We also take the opportunity to move some helpers that qtquickcontrols2
had added into the quicktestutils library where it makes sense, and
for the helpers that don't make sense to be there, move them into
quickcontrolstestutils.
We add the libraries to src/ so that they are internal modules built as
part of Qt, rather than tests. That way we can use them in a standalone
test outside of qtdeclarative.
Task-number: QTBUG-95621
Change-Id: I0a2ab3976fdbff2e4414df7bdc0808f16453b80a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit e310dadef7)
We still have to process the other properties there.
Change-Id: I043596dc55de885e6b746020633ec8b97d043ff2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 75f957f87a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
If an object is explicitly set as C++ owned, it should not be turned to
destructible in any case. explicitIndestructibleSet flag is used for
that and thus it should not be unset in any case.
This fixes an issue where a C++ owned object could be destroyed by GC
when it is added to a ListModel. An object is supposed to be set as
destructible implicitly when it is used as a return value from JS unless
explicitIndestructibleSet is set.
Fixes: QTBUG-96167
Change-Id: Iad06847e56e29dd1b20146be108d7f747d8474dc
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
(cherry picked from commit 219ca3bf2b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
It makes a QObject indestructable only if its ownership is determined.
This fixes an issue where a QObject created by createObject() in QML
becomes indestructable once it is appended to a ListModel.
Fixes: QTBUG-95895
Change-Id: I30647298977d7901dab938626e8f94b9910c21e3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Jaeyoon Jung <jaeyoon.jung@lge.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit 69e07c55ad)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Before this change, they were treated as script bindings, which are less
efficient, and could not be used in ListElement.
Fixes: QTBUG-95139
Change-Id: Ic66052c7f58b3ffdf1b7c0c169f42b4f99df62a1
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit e8121d9300)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
We store empty strings as null strings in StringOrTranslation;
consequently isSet will return false for such a string. However, we
still know that we are storing a string, and therefore need to return
a QVariant containing an empty string, instead of a null QVariant.
Amends 5022b91b31.
This fixes the "undefined" warning in Calqlatr (but changes nothing
about the fact that the example isn't reflective of modern QML
practices).
Task-number: QTBUG-54267
Change-Id: I83d871a79cd2bc0484f0eaf62d4ca345e39218aa
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 9be6a9327a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
If a QObject in the list is deleted from elsewhere, we need to zero it.
Amends commit 3edac1d0a70961e6f86564cc0a98339df6ac5964.
Fixes: QTBUG-94833
Change-Id: Ic33a5a0baa160824a34f353806dbfd876fa7123a
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit b2ee7364be)
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Previously QObject's could get garbage collected while in use.
This change fixes this by making them indestructible while in use and then restoring their previous state.
[ChangeLog][QtQml][QQmlListModel][Important Behavior Changes] ListModels now take ownership of the objects added to them, only releasing them after the object has been removed again. This may break existing solutions which rely on the object not being owned by the model.
Fixes: QTBUG-91390
Change-Id: Ifd37c90e13fb0b6ad8a5a06e89f9fc9a429f6316
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 16fc4cf366)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Change from the QVariant enum to the QMetaType enum and prefer typeId
over userType where possible
Change-Id: Ic89c55978d46cc23d23b8e9c82c475c0c220fae3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
[ChangeLog][QtQml] It is now possible to declare new QML components in
a QML file via the component keyword. They can be used just as if they
were declared in another file, with the only difference that the type
name needs to be prefixed with the name of the containing type outside
of the file were the inline component has been declared.
Notably, inline components are not closures: In the following
example, the output would be 42
// MyItem.qml
Item {
property int i: 33
component IC: Item {
Component.onCompleted: console.log(i)
}
}
// user.qml
Item {
property int i: 42
MyItem.IC {}
}
Fixes: QTBUG-79382
Change-Id: I6a5ffc43f093a76323f435cfee9bab217781b8f5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
The current code in ListModel simply did a reset of an existing
property, in case a role existed and was set to null/undefined. If the
role did not exist, the code would simply skip over the member and do
nothing.
However, this does not make any sense for newly inserted items, and
most likely indicates a misunderstanding of how ListModel works.
Creating an undefined/null role does not really make sense, as those
could only ever store a undefined/null value.
Change-Id: I4c1361647a82146565eaffe064598c94c748b4f5
Task-number: QTBUG-63569
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
ListElement::getProperty returns in turn a list model
The ModelObjectOwnPropertyKeyIterator should however return the concrete
values, and not some proxy object. This would cause funny return values
in the best case, and a crash in case of QTBUG-79083.
We therefore convert the nested model to a JavaScript array in
ModelObjectOwnPropertyKeyIterator::next, which avoids beforementioned
issues.
Fixes: QTBUG-79083
Change-Id: If038598ff1c3c59090e994aaba5fba94a6964224
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
The model types are not part of the core QML runtime and should only be
loaded if you explicitly import them. We cannot enforce that in Qt5 as
some of them are available from the QtQml import, but we can change it
in Qt6.
Change-Id: I1e49e84d748e352537ec2d4af901c034c91d038f
Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
Storing QObject pointers in a dynamic role model man end up crashing the
application once those objects get deleted.
As it looks impossible to make QVariant::fromValue<QObject*>(...) track
the life cycle in a binary compatible way, this patch fixes the crashes
by tracking with a QPointer at the level of QVariant storage. That's the
QQmlOpenMetaObject in the case of the dynamic role model. In principle a
similar approach is already in place for storage of QML declared
properties - this patch mirrors the approach.
Test cases provided by Ben Lau <xbenlau@gmail.com> and Chris Adams
<chris.adams@jollamobile.com>.
Task-number: QTBUG-35639
Change-Id: I0aee227cd2057654c2cb843c4ebb57ed2ec9a8bf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Calling QQmlListModel::append() with an empty JS array triggers an assert
in QAbstractItemModel::beginInsertRows() because it's called with
negative "last" parameter.
Change-Id: I202da260d79f2e6677c663c5785ff754c715fef8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
From now on we prefer nullptr instead of 0 to clarify cases where
we are assigning or testing a pointer rather than a numeric zero.
Also, replaced cases where 0 was passed as Qt::KeyboardModifiers
with Qt::NoModifier (clang-tidy replaced them with nullptr, which
waas wrong, so it was just as well to make the tests more readable
rather than to revert those lines).
Change-Id: I4735d35e4d9f42db5216862ce091429eadc6e65d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This is a regression introduced with commit
4876ea6a18. Where we previously always
returned the same JS object, we would afterwards return a new JS object
for every invocation, which breaks reference comparison. As we store the
JS wrapper for the list element in the QQmlData->jsWrapper we can avoid
repeated allocations. In order for that wrapper to keep working after
modifications (insertion, etc.) to the list model, we have to replace
the static element index with a reference to the node model meta-object,
which also has an element index that however is kept up-to-date by the
list model itself.
Change-Id: I4368de6b6d86687fe96fbf73bd60b80b69d7b058
Task-number: QTBUG-52017
Reviewed-by: Michael Brasser <michael.brasser@live.com>
This is a regression introduced with commit
3cc589c983, which in turn fixed a leak
with QV4::QObjectWrapper objects. Unfortunately the allocate() call into
the persistent (weak) value storage in the list model introduced a leak
of the weak value itself. This is fixed by replacing the free standing
weak value allocation with the use of the existing jsWrapper weak value
in the declarative data (QQmlData). That weak value is freed property in
the destroy() method of the QV4::QObjectWRapper. The extra QQmlData
allocation is hidden behind a unified allocation, similar to what we do
in void QQmlType::create(QObject **, void **, size_t) const.
Task-number: QTBUG-66189
Change-Id: I5351e3e484542709a6b210e84aa19b14d28e11ad
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
When falling back to the QObjectWrapper it will add in the extra parts
added when the roles were added to the object created by the model to
hold the data being returned. This was causing the last entry to be
duplicated and causing extra work too.
Task-number: QTBUG-54285
Task-number: QTBUG-62156
Change-Id: I2907477277df8d16db4491a4999f004433e4205c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This is a regression from commit
4876ea6a18, which avoided returning an
expensive QObject when calling get() but also lost the ability to
perform binding captures when accessing the properties. This change
restores the captures by performing them by hand in get() and also
triggering the notifiers directly when the values change, without
creating the QObject.
Task-number: QTBUG-52356
Change-Id: Ia429ffafd4032b63d3e592aa63bb0864a24e0965
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Part of 0e053528 was reverted in the merge, about lastTimestamp. It
will be applied later in separate commit.
qmltest::shadersource-dynamic-sourceobject::test_endresult() was
blacklisted on linux.
Conflicts:
.qmake.conf
tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
tests/auto/qmltest/BLACKLIST
tests/auto/qmltest/qmltest.pro
Task-number: QTBUG-53590
Task-number: QTBUG-53971
Change-Id: I48af90b49a3c7b29de16f4178a04807f8bc05130
If a role is unknown, trying to access it will crash in getExistingRole.
Fixed that and now return QVariant() for unknown roles.
Change-Id: Iad5c1292a4faee893fbc5a69984cf776aca85d70
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
From Qt 5.7 -> tools & applications are lisenced under GPL v3 with some
exceptions, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/
Updated license headers to use new GPL-EXCEPT header instead of LGPL21 one
(in those files which will be under GPL 3 with exceptions)
Change-Id: I04760a0801837cfc516d1c7c02d4f503f6bb70b6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Use character literals where applicable.
Change-Id: Ib0e618752fbc762a73a0a91c43efab61ef2c9687
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Extending QQmlListModel by setData allows us
to modify the content of the ListModel from
within a delegate by doing an 'model.someProp = someValue'
assignment.
Change-Id: I87e4c31aca3813f099b2a4fd694beb2492a03bd0
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
- Replace Q[TRY]_VERIFY(pointer == 0) by Q[TRY]_VERIFY(!pointer).
- Replace Q[TRY]_VERIFY(smartPointer == 0) by
Q[TRY]_VERIFY(smartPointer.isNull()).
- Replace Q[TRY]_VERIFY(a == b) by Q[TRY]_COMPARE(a, b) and
add casts where necessary. The values will then be logged
should a test fail.
Change-Id: I8cc97fd9b48fc789a849e9527c292c4e05accd97
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.
Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
The merge conflict is about the removal of "d1" from the register
set on ARM, but that was already done in dev in commit ddb33ee9ba
The change in src/quick/scenegraph/coreapi/qsgrenderer.cpp with commit 2414f1675e
was reverted to what it was before, per Laszlo's advice.
Conflicts:
src/qml/jit/qv4isel_masm.cpp
Change-Id: I7bce546c5cdee01e37853a476d82279d4e72948b
The custom parser design used to be so that the custom parser operates on the "AST",
creates its own binary representation of the data it needs, stores it in a QByteArray
and gets that at object instantiation time. That meant serializing everything necessary.
With the introduction of the "binary" QML data structure, that process of serialization
becomes obsolete and would require extra work in the custom parsers for example for QQuickStates
to store the translation parameters.
The clean solution is to eliminate this unnecessary serialization process and
instead let the custom parsers do a verification pass at type compile time and
then simply operate directly on the QV4::CompiledData::Bindings at object
instantiation time. That simplifies the code, and allows for support of
translations throughout all list model properties.
Additionally this speeds up the creation of state objects and reduces memory
consumption. Previously a text: qsTr("foo") binding in states would result in
an actual java script binding. After this patch it is merely stored as a string
and translated at object instantiation time.
Change-Id: I7550274513f54abb09a0ab4de51c4c0bcdb23cae
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Call beginInsertRows(), beginMoveRows() and beginRemoveRows() before
the change to ensure that rowsAboutToBeInserted(), rowsAboutToBeMoved()
and rowsAboutToBeRemoved() get emitted before the change as appropriate.
NOTE: This patch solves the problem for the most common use case, when
ListModel is used without WorkerScript. QQmlListModelWorkerAgent needs
similar changes in order to fix the signals when ListModel is used with
WorkerScript (QTBUG-39321).
Task-number: QTBUG-39279
Change-Id: Idec5167d70b242f6f7d8b7cff008e130afc62505
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
This is a smaller fix suitable for the release branch, merely adding support
for translations to the bytearray compilation step for states and ensuring a
consistent error message when qsTr is used in list models.
The proper fix will be done in dev that eliminates the entire intermediate
QByteArray storage for custom compilers.
Task-number: QTBUG-38492
Change-Id: If5171f16eb742c718e48b8bbcb265b0c241cd5e7
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
We can store them as regular strings. This has the advantage that the
entire special handling from the custom parser of the list model goes away,
we don't need astForBinding in QQmlCustomParser anymore neither and types
with a custom parser can now generally benefit from the expression simplification
pass.
Change-Id: I39d1b76edd1273d8c73b847aed71f7bcce37d877
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
The elements are still inaccessible, but at least it doesn't crash. This is
consistent with the behavior in Qt 5.0, where it didn't crash because the v8
object handle returned an empty array for the property names because the
individual array element wasn't an object.
Bug QTBUG-12117 tracks support for arrays in list models.
Task-number: QTBUG-35891
Change-Id: Ief446341344977a1473bca474ca5ba934e950468
Reviewed-by: Albert Astals Cid <albert.astals@canonical.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
There's no reason to disallow calling model.set() with
an ArrayObject as argument.
Change-Id: I44baad677ca34e1fb4188b89f0a548af84580b4f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
In the listmodel test an error description was not converted to a
string.
In the pathview test, number literals are always interpreted as double,
but qreal can also be float, which lead to failing tests. Constructor
usage prevents "expected data of type 'float', got 'double'".
Change-Id: I0c760486de0ba4df6a5e9a33e9528ca7d7a1a63e
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
They're already in the QtQml module, but were left in the QtQuick import
because they were considered to be of minimal use without QtQuick types.
QtQml types are being developed would could make ListModel useful
without QtQuick, indicating that they should no longer be considered
QtQuick depedent.
Change-Id: I31499f2cc23baf4bc70fb451ba164408bed89ff6
Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>