Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Second Listview based on first displaying only items when variable is not null
Qt 6.11 is out! See what's new in the release blog

Second Listview based on first displaying only items when variable is not null

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 181 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eikoot
    wrote on last edited by
    #1

    I'm working on warehouse application. In first tab I created list of items, where the user can add products to bucket. The amount of products is variable. I used following code:

    class Product : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QString name READ getName CONSTANT)
        Q_PROPERTY(double price READ getPrice CONSTANT)
        Q_PROPERTY(int amount READ getAmount WRITE setAmount NOTIFY amountChanged) //amount in bucket
        Q_INVOKABLE void increaseAmount()
        ...
    
    
    class Warehouse: public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QList<Product*> wares READ getWares NOTIFY wareAdded)
    
    
        Warehouse {
            id: mainWarehouse
        ...
        ListView {
            model: mainWarehouse.wares
            delegate: 
               {Grid
                  {Text{ // info about product}
                  Button{
                      onClicked: {model.modelData.increaseAmount();
    

    Now I want to create a second tab in my application, where I display only products added to bucket. What's the best way of doing this? Should I create second Q_PROPERTY QList<Product*> with getter, in which will be checked if amount > 0? It seems for me as not the best solution here, but I have no idea how to solve it better. I'm not sure, if my approach with QList as Q_Property is correct. Besides of that, I'm not sure, if the new List will correctly recognize, when new items will be added to bucket.

    A side question: how to catch the signal amountChanged, which is called, when the button from listElement is clicked (calling method increaseAmount)? I would like to display a dialog, when the user is informed, that a product was added to bucket. The best would be, if I will be able to display a info about added product.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved