Note that there are some explanatory texts on larger screens.

plurals
  1. POQT QML import ListModel from C++ to QML
    primarykey
    data
    text
    <p>How can i change the model of a PathView with c++ code ? i add an objectName to my pathView to find it, then i change the property like this, but when i do that, my list is empty :</p> <pre><code>QDeclarativeItem *listSynergie = myClass.itemMain-&gt;findChild&lt;QDeclarativeItem*&gt; ("PathViewInscription"); listSynergie-&gt;setProperty("model", QVariant::fromValue(dataList)); </code></pre> <p>My data list is fill like this :</p> <pre><code>QList&lt;QObject*&gt; dataList; dataList.append(new synergieListObject("Item 1", "1",false)); dataList.append(new synergieListObject("Item 2", "2",true)); dataList.append(new synergieListObject("Item 3", "3",false)); dataList.append(new synergieListObject("Item 4", "4",false)); </code></pre> <p>This is the code of my PathView :</p> <pre><code>PathView { objectName: "PathViewInscription" Keys.onRightPressed: if (!moving) { incrementCurrentIndex(); console.log(moving) } Keys.onLeftPressed: if (!moving) decrementCurrentIndex() id: view anchors.fill: parent highlight: Image { source: "../spinner_selecter.png"; width: view.width; height: itemHeight+4; opacity:0.3} preferredHighlightBegin: 0.5 preferredHighlightEnd: 0.5 focus: true model: appModel delegate: appDelegate dragMargin: view.width/2 pathItemCount: height/itemHeight path: Path { startX: view.width/2; startY: -itemHeight/2 PathLine { x: view.width/2; y: view.pathItemCount*itemHeight + itemHeight } } } </code></pre> <p>and the code of ListModel :</p> <pre><code>ListModel { id: appModel ListElement { label: "syn1"; value: "1"; selected:false} ListElement { label: "syn2"; value: "2" ; selected:false} ListElement { label: "syn3"; value: "3" ; selected:false} } </code></pre> <p>what's wrong ? Thanks !</p> <p><strong>EDIT :</strong></p> <p>the code of the appDelegate :</p> <pre><code> Component { id: appDelegate Item { width: 100; height: 100 Text { anchors { horizontalCenter: parent.horizontalCenter } text: label smooth: true } MouseArea { anchors.fill: parent onClicked: view.currentIndex = index } } } </code></pre> <p>the code of my object :</p> <pre><code> #ifndef SYNERGIELISTOBJECT_H #define SYNERGIELISTOBJECT_H #include &lt;QObject&gt; class synergieListObject : public QObject { Q_OBJECT Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) public: synergieListObject(QObject *parent=0); synergieListObject(const QString &amp;label,const QString &amp;value,bool selected, QObject *parent=0); QString label() const; void setLabel(const QString &amp;label); QString value() const; void setValue(const QString &amp;value); bool selected() const; void setSelected(const bool &amp;selected); signals: void labelChanged(); void valueChanged(); void selectedChanged(); private: QString m_label; QString m_value; bool m_selected; }; #endif // SYNERGIELISTOBJECT_H </code></pre> <p>c++ my object :</p> <pre><code>#include "synergielistobject.h" synergieListObject::synergieListObject(QObject *parent): QObject(parent) { } synergieListObject::synergieListObject(const QString &amp;label,const QString &amp;value,bool selected, QObject *parent): QObject(parent), m_label(label), m_value(value), m_selected(selected) { } QString synergieListObject::label() const { return m_label; } void synergieListObject::setLabel(const QString &amp;label) { if (label != m_label) { m_label = label; emit labelChanged(); } } QString synergieListObject::value() const { return m_value; } void synergieListObject::setValue(const QString &amp;value) { if (value != m_value) { m_value = value; emit valueChanged(); } } bool synergieListObject::selected() const { return m_selected; } void synergieListObject::setSelected(const bool &amp;selected) { if (selected != m_selected) { m_selected = selected; emit selectedChanged(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload