Results 1 to 7 of 7

Thread: Getting a specific list element

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Getting a specific list element

    Unfortunately, I find that the documentation on Qt Quick and QML to be sadly insufficient. What's there is either so basic as to be useless or so involved that it is impossible to understand. When I was looking at XmlListModel last night, the link takes you to a generic List model page that describes all of the various QML list models. The links on -that- page for more information on XmlListModel take you right back to the same page.

    The best I can suggest is to go to the Qt Quick Examples and tutorials and start studying things that sound like they might be useful.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. #2
    Join Date
    May 2017
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Getting a specific list element

    So it turns out I am using QtRpi which uses QT5.7 cross compiled from a Linux machine to a raspberry pi. XML is not a supported module.

    I do think I found the answer in the stocqt project. In StockListView.qml they do the following.

    First they declare these variables up top


    property string currentStockId: ""
    property string currentStockName: ""


    Then they use a model.get to get the data for the active element.
    onCurrentIndexChanged: {
    if (currentItem) {
    root.currentStockId = model.get(currentIndex).stockId;
    root.currentStockName = model.get(currentIndex).name;
    }
    }

    I was playing with it and it pulls the element that is active in currentIndex. I can't try it with my stuff until Monday. My wife will kill me if I mess with this on the weekend.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Getting a specific list element

    XML is not a supported module.
    Surprising. The Qt source code is available, so you could try building the XML module yourself if you are adventurous. If you are more adventurous, you can install a native compiler toolchain on your RPi and build it there instead of cross-compiling.

    In any case, you don't really need XML, it is just a convenient way to store hierarchical data in a readable and easily parseable way. You could also use SQLite to make a recipe database; SQLite is implemented as a single source / header pair and you simply compile it as part of your project. You don't even need the database support from Qt.

    A database might contain three tables:

    - A Recipes table, with fields for RecipeID, Name, Description, and whatever else
    - An Ingredient table, with fields for Ingredient ID, Name (this table is independent of recipe - the same ingredient can appear in more than one recipe)
    - A RecipeIngredients table linking RecipeID and IngredientID, with fields for Quantity and Unit

    From the list view containing recipes, when the user clicks a recipe line, retrieve the RecipeID by searching the Recipes table for the Name.
    From the RecipeIngredients table, retrieve all IngredientID entries where RecipeID matches
    From the Ingredients table, retrieve the Name for each matching IngredientID and display them in the ingredients list view.

    My wife will kill me if I mess with this on the weekend.
    "Honey, I'm trying to improve my skills so I can find a better job and make more money so we can have better vacations... I don't have the time to do this during the week."
    Last edited by d_stranz; 13th May 2017 at 19:06.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting a specific list element

    in addition to d_stranz's answers:

    I would would pack the whole data in to one treemodel.
    Each recipe is a child of the root element - and it contains the name of the recipe.
    Each recipe element is a parent to ingredient elements.

    Also, remember that how data is stored and how it is in memory can vary, and it often does differ.
    I'd do what would be the easiest thing to do, for me.
    If you are very strong with XML, do it in XML, if you are strong with MySQL, you can do in MySQL, etc
    I would do it in a text file, using QSettings.
    Its easy, and you can open it with any editor and still know what the data is, and even mend it manually if needed.
    Well, I am a C++ guy, so if you have found something else that works for you better with QML, stick with it, here is just another view on things, maybe it can give you some ideas, maybe not.

    As I said, in memory I'd use a tree-model and in your recipe list I'd simply show the first level of children (the recipe names).
    For each selected recipe I'd get the list of its children and show that in a list of ingredients at the bottom.

    Since you have asked about QML documentation here is a good link if you don't know it yet:
    https://qmlbook.github.io/
    And for your case you probably would like to jump to:
    https://qmlbook.github.io/en/ch06/index.html
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. A list box with an specific style checkbox
    By wxShayan in forum Newbie
    Replies: 1
    Last Post: 30th December 2012, 12:53
  2. Replies: 9
    Last Post: 23rd April 2012, 13:53
  3. How to add color to the List View Element in QML?
    By harish in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2012, 11:29
  4. how to access ith element of an qstring list?
    By aurora in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2011, 09:37
  5. Replies: 9
    Last Post: 8th March 2011, 08:35

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
  •  
Qt is a trademark of The Qt Company.