[Development] QML, Widgets, and setParent

Alan Alpert 416365416c at gmail.com
Thu Oct 31 21:56:30 CET 2013


I'd argue that it's setParent with the bug. It's conceptually valid to
have a QWidget with a QObject parent but no QWidget parent, but it
won't really show up until you try to use them in QML. If you do this
with non-QML QWidgets, then it won't show up on screen so the user
will think they've made an error (but with QML there's an intermediate
state it goes through even in a correct usage case).

QML as a language requires that you can set the QObject::parent on
instances of QML types, so if that QObject assert is valid it means
you can't use widgets in QML without hacks (specifically, that exact
hack you found already which doesn't allow intermingling).

--
Alan Alpert

On Thu, Oct 31, 2013 at 12:17 PM, Konrad Rosenbaum <konrad at silmor.de> wrote:
> Hi,
>
> I'm trying to port KDAB's DeclarativeWidgets[1] to Qt5. I've got it running
> for trivial QML files, however as soon as there are child widgets the
> running program aborts.
>
> The abort is caused by QObject::setParent, which contains this little gem:
> Q_ASSERT(!d->isWidget);
>
> Apart from not understanding why there is a significant difference between
> QObjects and QWidgets in regards to parenting...
>
> There used to be code that handled this in qqmlvme.cpp[2], but it has been
> disabled by an #if 0 . Apparently to remove dependencies on QtWidgets from
> QtQml.
>
> I kind of ran out of ideas on how to solve this. Should I consider
> setParent, qqmlvme or the direct use of QWidgets as a bug?
>
>
>
>         Konrad
>
>
> [1] It enables you to create widget based GUIs using QML.
> git://github.com/KDAB/DeclarativeWidgets
>
> [2] In 5.2 beta this is line 627 in qqmlvme.cpp. It's Halloween. Go ahead,
> look at scary code! ;-)
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>



More information about the Development mailing list