diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-11-29 14:04:27 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2017-09-21 09:00:35 +0000 |
commit | 82fbaa78f3840bcc289adc4e1ec64e337346f148 (patch) | |
tree | 88111a1b65d04f2d990c43f5b33f01d981df04bb /src/qml/qml/qqmlobjectcreator.cpp | |
parent | d8d3259b2340baed2e7f8273907bd0bb5598b540 (diff) |
Fix support for creating QWidgets in QML
When creating QWidgets, it is important to replace any call to
QObject::setParent with QWidget::setParent. We do this now with the
hook introduced in commit fc8adfea9f5e09e5f47ac4e592e5d9db471caede in qtbase.
Change-Id: I2e069696b7ceb7f3b77d0f17e058f5a00ca4a029
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlobjectcreator.cpp')
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 11d090a415..26bdf1a94f 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -1113,8 +1113,16 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo return 0; } } - if (parent) + if (instance->isWidgetType()) { + if (parent && parent->isWidgetType()) { + QAbstractDeclarativeData::setWidgetParent(instance, parent); + } else { + // No parent! Layouts need to handle this through a default property that + // reparents accordingly. Otherwise the garbage collector will collect. + } + } else if (parent) { QQml_setParent_noEvent(instance, parent); + } ddata = QQmlData::get(instance, /*create*/true); ddata->lineNumber = obj->location.line; |