O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing the GroceryItems entity

The create method of entity::GroceryItems must ensure that:

  • The new item is added to the list
  • The list is sorted
In a real setting, the creation should also trigger that the new item is persisted as a record in whatever data repository happens to be in use and, possibly, that the data is fetched again from the repository to make sure synchronization has happened. For the time being, we will focus on the item addition and list sorting steps.

Having already implemented the sortBy method, to implement the create method, we can just flag isSortedByNameAsc as false, add a new record to the list, and resort the list:

// grocery_items.cpp...void GroceryItems::create(const QString& name){ isSortedByNameAsc = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required