Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Is it actually possible to use a C++ QList as a model for a QML PathView?

    QML and Qt Quick
    1
    3
    3261
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tedmiddleton last edited by

      I've already asked this question on stack overflow, but I thought I'd ask here where the real Qt experts are.

      "http://stackoverflow.com/questions/15753419/qt-qml-data-model-doesnt-seem-to-work-with-c":http://stackoverflow.com/questions/15753419/qt-qml-data-model-doesnt-seem-to-work-with-c

      The executive summary is that if I have a QML ListModel, I can set that as the model for either a QML ListView or a QML PathView. If I have C++ objects in a QList<>, which is what some of the QML data model examples do, I can create a working model for QML ListViews, but not QML PathViews. There seems to be something that ListView has that QList<MyClass> doesn't - some glue that gets PathView working but is missing when I make my QList.

      I'm using Qt 4.8.4 on Windows. Any ideas? Does anyone know of a sample or an example that does this? Something that populates a PathView with a C++ model? Any C++ model, QList-based or QAbstractListModel-based, would be fine.

      1 Reply Last reply Reply Quote 0
      • T
        tedmiddleton last edited by

        So I tried out a horrible hack - here it is:

        main.cpp:
        @
        ...
        dataList.append( new DataObject( "c++ entry6 (purple)", "purple" ) );

        QmlApplicationViewer viewer;
        QDeclarativeContext * context = viewer.rootContext();
        context->setContextProperty( "cppModel", QVariant::fromValue(dataList) );
        context->setContextProperty( "cppModelCount", QVariant::fromValue(dataList.count()) );
        viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
        ...
        

        @

        cpptest.qml:

        @
        ...
        interactive: true
        //model: qmlModel
        model: cppModel

            delegate: Rectangle {
                width: 100
                height: 100
                color: colour
                Text {
                    anchors.centerIn: parent
                    text: name
                }
            }
        
        
            path: Path {
                startX: - my_path_view.width * cppModelCount / 2 + my_path_view.width / 2
                startY: my_path_view.height / 2
                PathLine {
                    x: my_path_view.width * cppModelCount / 2 + my_path_view.width / 2
                    y: my_path_view.height / 2
                }
            }
        ...
        

        @

        This actually produced the expected result. But its a terrible hack. Why is this not working properly? I can't believe that this is as-designed - it really does seem to be a Qt bug in the Path object, or the C++ bindings. cppModel.count, according to my debug printouts in the qml, is never available - in fact, the object that cppModel is bound to has no members at all.

        I've build Qt before and I have the source - is there any place that anyone could point me to where I could start debugging this?

        1 Reply Last reply Reply Quote 0
        • T
          tedmiddleton last edited by

          I got some help from a couple of experts on IRC (#qt-qml) last night and my example is working now. I've answered the StackOverflow question that I linked to above if anyone is interested.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post