Results 1 to 4 of 4

Thread: Access to model properties in QML when lists are created in C++

  1. #1
    Join Date
    Dec 2009
    Location
    Barcelona
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Access to model properties in QML when lists are created in C++

    Hello,

    I am using qmlifyproxy library (http://www.qtcentre.org/wiki/index.p...LifyProxyModel) to call a model written in C++ that displays a Grid of images. Until now images are displayed fine.
    My problem is: I cannot give to the "model: MemoryModel" sentence in the code piece below an id property visible for QML to enable access to the model properties (in my case I need to use "get" and "move" properties as detailed in the main.qml code).

    when I write the model call sentence in the code below with:
    model: memoryModel
    there are no errors obviously, but it does not work because I cannot access the properties

    But, the code below:
    main.qml.txt
    with the sentence:
    model: memoryModel { id: icons }
    to enable access to use the properties, I get the following error:
    file:///../SQLListViewProxy-build-desktop/qml/SQLListViewProxy/main.qml:15:14: Expected type name model: memoryModel { id: icons}

    and I can not continue...

    To clarify, my question is: How is it possible in a model created in C++ to give an id property visible from QML to enable access to the model properties as "get" or "move"?

    main.cpp where "memoryModel" is referred is attached.
    memoryitem.qml to provide more context info, also.

    Cheers,

    Carlos
    Attached Files Attached Files
    Last edited by carlossst; 8th February 2011 at 21:40. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access to model properties in QML when lists are created in C++

    Please try to explain your problem more clearly. What is the "id" property and what is it used for? "model" should state an identifier bound to a data model, nothing else. If you wish to set the "id" property of your model to "icons" then you need to run the following javascript expression somewhere:
    javascript Code:
    1. memoryModel.id = "icons"
    To copy to clipboard, switch view to plain text mode 

    But this 'somewhere' can't be the statement binding a model to your view, the syntax is simply wrong.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2009
    Location
    Barcelona
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Access to model properties in QML when lists are created in C++

    Thanks for answering,
    Let me clarify, of course:
    1) From a C++ tabular list model (composed of strings: paths to files of images and descriptor texts) it is created a list model declared as "memoryModel" in QML's GridView. (See main.cpp and main_new.qml)
    2) GridView displays images and texts properly
    3) a QML ListModel needs an id so all members of ListModel can be referenced(for example "get" and "move"). (See main_new.qml)
    4) I have declared the sentence "model: memoryModel { id: icons }" in main.qml to enable usage of ListModel members icons.get and icons.move

    The issue is: the sentence above gets a compiler error. As a consequence, I do not know how to define a valid id (as "icons" in the code) to use ListModel members in QML.
    The reason is that memoryModel is not ListModel declared in QML but imported from C++, probably, and I do not know how to define a valid id in this case to enable usage of ListModel members in QML.

    Hope it helps,

    Carlos
    Attached Files Attached Files
    Last edited by carlossst; 9th February 2011 at 11:37.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access to model properties in QML when lists are created in C++

    The id of the model is the name of the property you export from within C++ using QDeclarativeContext. You can of course provide an alias to it using regular QML means.

    Qt Code:
    1. QDeclarativeContext *context = view.rootContext();
    2. context->setContextProperty("FileModel", &proxy); // "FileModel" is the id of the model
    To copy to clipboard, switch view to plain text mode 

    In the example above "FileModel" represents an object and not a type. In your code "MemoryModel" is the id of your model object. If you want to have more memory models you need to export each and every one in C++ using different property names.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    carlossst (9th February 2011)

Similar Threads

  1. Hi all, some about lists and views
    By kosasker in forum Newbie
    Replies: 4
    Last Post: 24th January 2011, 13:55
  2. Replies: 4
    Last Post: 9th February 2010, 18:08
  3. How to access Widgets created in Tab View
    By kapoorsudhish in forum Newbie
    Replies: 5
    Last Post: 23rd October 2009, 14:12
  4. Access from Delegate to Model
    By starcontrol in forum Qt Programming
    Replies: 5
    Last Post: 11th April 2008, 13:26
  5. When sort the lists?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2006, 17:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.