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 8431469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:51:50+00:00 2026-06-10T05:51:50+00:00

(EDITED) In original question I erroneously assumed that GridView natively use 2-dimensional model. Indeed,

  • 0

(EDITED) In original question I erroneously assumed that GridView natively use 2-dimensional model. Indeed, it takes a list of elements similarly as other QML
views. To make the question and answers more understandable I changed given code
slightly. Moreover, I added working soluton based on answers.

In main program I define an instance of QStandardItemModel:

QScopedPointer<QApplication> app(createApplication(argc, argv));
QmlApplicationViewer viewer;

QStandardItemModel* cppmodel = new QStandardItemModel();
for (int i=0; i<100; i++) {
    QStandardItem* item = new QStandardItem(QString("%1").arg(i,2,10,QChar('0')));
    cppmodel->appendRow(item);
}

Then, I register the model to QML with:

viewer.rootContext()->setContextProperty("cppModel",cppmodel);

QStandardItemModel is a table,isn’t it? Then, how can I write a delegate to
show items in a simple GridView:

    GridView {
        model: cppModel
        delegate: Rectangle {
            Text { text: ??? } //WHAT MUST BE USED HERE ???
        }
    }

Do I have to use named roles or can I just use properly created indices?

  • 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-06-10T05:51:51+00:00Added an answer on June 10, 2026 at 5:51 am

    Maybe It helps you:
    Using QStandardItemModel in QML

    Also you can try such code:

    GridView {
       anchors.fill: parent
       model: cppModel
       delegate: Rectangle {
          Text {
             text: display;
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, i kind of asked the wrong question so I've edited the original question.
I have edited the original question since the same error is occurring the difference
In response to the helpful comments, I have edited the original question (where I
Edited the question due to progressive insights :-) I am creating an app that
[EDITED: I left the original question below, with some more context and code to
Edited Original question was about trouble with reconnecting (close() and shutdown() confusion). The below
Note: I have edited the original question based on comments and answers. My question
This question has been edited to ask about a specific example as the original
Edited to make question more concise. Can i use the outerWidth() value within the
Please note, sarnold has heavily edited the question; the original question, in its entirety,

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.