[Interest] Only 9 QML components can be created partially?

Richard Weickelt richard at weickelt.de
Sun Oct 1 11:16:55 CEST 2017


Hi,

the following example fails after 9 loop iterations:

#include <QtCore>
#include <QtQml>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    QQmlEngine engine;
    QQmlComponent* components[47];
    QObject* objects[47];

    for (int i = 0; i <= 47; i++)
    {
        components[i] = new QQmlComponent(&engine);
        components[i]->setData("import QtQml 2.0\n QtObject{}", QUrl());
        objects[i] = components[i]->beginCreate(engine.rootContext());
        Q_ASSERT(objects[i] != NULL);
    }
}

Command line:
  $ test
  QQmlComponent: Component creation is recursing - aborting
  ASSERT: "objects[i] != NULL" in file /XXX/testmain.cpp, line 16

I do not see, how this relates to recursion. The root cause seems to be
http://code.qt.io/cgit/qt/qtdeclarative.git/commit/?id=19c0a31319148d4ac716f7cb3295891b5a3b20d9

In fact, this patch does not detect recursive component creation. But it
triggers when more than 9 components are partially created, no matter in
what structure/order.

Q1: Is the implementation in QQmlComponent wrong?
Q2: Is my use case a valid one?

Background: I need to create a couple of QML components, but I cannot
complete creation until all components are partially loaded. Each component
has a (constant) property that needs to be evaluated first. Depending on
that, some properties will be injected in the other components.

Q3: Can I achieve that in a different (but simple) way?

Thanks
Richard



More information about the Interest mailing list