Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7430977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:13:26+00:00 2026-05-29T09:13:26+00:00

Well, i’m learning to work with QML and i have one doubt. In my

  • 0

Well, i’m learning to work with QML and i have one doubt. In my example, i have a ListModel with ListElements at QML and i have a QML main file with a rectangle, PathView etc.

I have a QWidget also, than is my main window. In this QWidget i include the QML UI like a component. Ok!

How can I handle QML ListElements by using C++?
Note: when I say “to handle”, I want to say include an element for example.

Below are some parts of my code…

QML containing my ListElement, called “Menu1”:

import QtQuick 1.0

ListModel {
    id: listMovieModel
    ListElement { name: "Image 1"; iconSource: "pics/image_1.jpg" }
    ListElement { name: "Image 2"; iconSource: "pics/image_2.jpg" }
    ListElement { name: "Image 3"; iconSource: "pics/image_3.jpg" }
    ListElement { name: "Image 4"; iconSource: "pics/image_4.jpg" }
    ListElement { name: "Image 5"; iconSource: "pics/image_5.jpg" }
    ListElement { name: "Image 6"; iconSource: "pics/image_6.jpg" }
}

My main QML:

Rectangle {
    width: 500
    height: 600
    color: "transparent"

    PathView {
        id: view
        focus: true
        width: parent.width
        height: parent.height + y
        y: -150
        model: Menu1 {} //First QML showed
        delegate: Image {
            source: iconSource
            width: 64
            height: 90
            scale: PathView.isCurrentItem ? 3.5 * y / parent.height : 2.0 * y / parent.height
            z: y
            smooth: true
        }
        path: MyGeometricFigure { //This a another file, but is confidential
            width: view.width
            height: view.height
        }
        preferredHighlightBegin: 0
        preferredHighlightEnd: 0
        highlightRangeMode: PathView.StrictlyEnforceRange
        Keys.onLeftPressed: decrementCurrentIndex()
        Keys.onRightPressed: incrementCurrentIndex()
    }
}

And as I use QML like a component for my QWidget:

MainForm::MainForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainForm)
{
    ui->setupUi(this);
    this->resize(1024, 576);

    QDeclarativeView *myQMLTest = new QDeclarativeView(QUrl::fromLocalFile("myMainQML.qml"));
    myQMLTest->setStyleSheet(QString("background: transparent; width: 600px"));

    this->ui->frameListVideoGallery->layout()->addWidget(myQMLTest);
    myQMLTest->setFocus();
    myQMLTest->installEventFilter(this);
}

I saw some articles about this, but I am not able to change my LisModel using C++. I saw here http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#c-data-models and here in examples using PathView http://doc.qt.nokia.com/4.7/qdeclarativeexamples.html

Can someone help me?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:13:27+00:00Added an answer on May 29, 2026 at 9:13 am

    Alright. I think you can do something like this:

    In your main QML-file add simple function.

    Rectangle {
        // ...
    
        function append(newElement) {
            view.model.append(newElement)
        }
    
        PathView {
            id: view
    
            // ...
    
            model: Menu1 {} //First QML showed
    
            // ...
        }
    }
    

    This method will just call a corresponding method from ListModel. More supported methods you can find there.

    Then all you need is to call this method from C++ code. You can do this in such manner:

    MainForm::MainForm(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::MainForm)
    {
        ui->setupUi(this);
        this->resize(1024, 576);
    
        QDeclarativeView *myQMLTest = new QDeclarativeView(QUrl::fromLocalFile    ("myMainQML.qml"));
        myQMLTest->setStyleSheet(QString("background: transparent; width: 600px"));
    
        QVariantMap newElement;  // QVariantMap will implicitly translates into JS-object
        newElement.insert("name",       "Image 13"         );
        newElement.insert("iconSource", "pics/image_13.jpg");
    
        QMetaObject::invokeMethod(
            myQMLTest->rootObject(),                          // for this object we will call method
            "append",                                         // actually, name of the method to call
            Q_ARG(QVariant, QVariant::fromValue(newElement))  // method parameter
        );
    
        this->ui->frameListVideoGallery->layout()->addWidget(myQMLTest);
        myQMLTest->setFocus();
        myQMLTest->installEventFilter(this);
    }
    

    You should check this for more information.

    Also you can choose another approach: to pass some data via qml properties (using QDeclarativeEngine and QDeclarativeContext) and then handle this data and your list-model right in JavaScript code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well i have used an html file like these in iframe <iframe src=sample.html></iframe> is
Well I have a view of this type of hierarchy Main View (having some
Well, this one is my XML file <?xml version=1.0 encoding=utf-8?> <config> <setup> <Test>10</Test> <Copy>
well I have a simple text file where I have my textual data filled,
Well, I have a class Customer (no base class). I need to cast from
Well i have a gridview where i have defined the columns on my own
Well i have a transparent div or the background is set to transparent :)
Well after much messing about I have finally got a query that gives sales
Well, i have the following need: create 3 dropdownlist with dependencies. My table in
Well im here because i have a problem. i have code that was created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.