Quantcast
Viewing all articles
Browse latest Browse all 4972

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

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?

Viewing all articles
Browse latest Browse all 4972

Trending Articles