Cannot assign object to list [SOLVED]

  • I've steadily been updating our projects to use QtQuick 2.0. I'm getting a really strange error at runtime and I haven't been able to pinpoint its cause. Google has also been of no help; the forums are my second to last hope other than banging my head against the wall.

    My QML code is nothing special:

    import QtQuick 2.0

    Item {
    Connections {
    target: types //< Irrelevant as to what this is, it's an exposed QObject.
    onStart: {



    The QML Engine when running points at the "Connections" line reporting that "Cannot assign object to list". The strange thing about this error is that it isn't consistent. I do consistently see these errors but they complain about random QML Elements. I've seen it report the same error for Connections, Item, Rectangle, and QtObject. Each time I run, I get a different set of runtime errors. My theory on this is that the QML Engine is just processing different QML Files each time- but I can't be sure.

    Has anyone experienced this before? I get the feeling that somewhere in my code it may be trying to import QtQuick 1.1- but this is just a theory as I've yet to find it. Thanks in advance!

    [edit: added missing coding tags @ SGaist]

  • Could you provide a sample that runs? The example you provided doesn't seem valid QML code.

  • Posting QML won't help to solve the issue at this time. I am trying to come up with an example, however this is proving to be difficult. I do not believe this is a QML issue. I believe that this is some sort of QML Engine setup issue. The code above was just provided as a way to illustrate that it was failing on Connections not necessarily as a proof of error.

    Since I posted this I've tried a couple of different approaches. For example, I've tried aliasing the QtQuick import:

    import QtQuick 2.0 as QQ

    QQ.Item {
    // blah blah blah

    This did not seem to help. The failure once again is stating "Cannot assign object to list". The only place in the Qt code where this error message seems to exist is in QQmlCompiler:

    So somehow the QML Compiler thinks its getting some sort of object to be added to a list. I haven't figured out how to sneak a breakpoint in here to find out more (this will probably be what I try next). I guess the next question is where is this list that it is trying to build? I assume it's the main list of children for the root item (or something similar). In which case, how are all of these root object types not mappable? The only theory I keep coming back to is that it is building the wrong type of item for the associated engine. Can this even happen?

    Sorry to be a little short about the example- the example could be any sort of "valid" QML.

    Another theory I have is that we may have too many objects created in QML. Can this ever be a problem? Is there a limit to how many QML objects exist? Once again thanks in advance!

  • Once again I shoot myself in the foot. I'm posting this for the benefit of everyone else since it was such a stupid thing that I did:


    What's going on here (as far as I can tell) is that QObject* was bound to the name QQuickItemLayer in the Qt Meta Object system. The issue with this is that the subsequent QML elements are registered also using these same types. I know this is a vague explanation- but it boils down to the meta type system. Taking this line out in my code fixed the issue I was seeing. I'm writing a blogpost elsewhere to fully explain some of the things I tried since a lot of it is off topic.

    The reason I put this line of code in was that the QmlEngine was reporting that this was an issue in a console app. I thought I was being clever by providing this type (it silenced the console errors). However, it just caused a bigger issue.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.