Enginio QML Examples - Todos

The Todo example shows the EnginioModel usage in Qt Quick.

In this example a simple list of objects is displayed in a ListView. Each item in the list is a "To Do" object which can be done or not yet done. Todos can be added and removed (when hovering with the mouse).

[Missing image todolist.png]

In this simple schema, the objects will only have two properties that are added to the default properties (such as creation date, which always exists): a string title and a bool completed. The object type will be created when a call to create, or, in this case, a call to EnginioModel::append() is made.

A todo object will look like this in JSON:

 {
   "title": "Buy Milk",
   "completed": false
 }

The example uses Qt Quick Controls, Layouts, and Enginio.


The first step is to create an Enginio model and its Enginio client with the backend configuration. To get nice debug output in case something goes wrong, the client's onError signal handler is implented. Since the error is a JSON object, JSON.stringify is used to format it to a string.


A ListView is used to display the list of Todos. In the delegate, the properties of the Enginio objects are used.


It is easy to add a new Todo object to the model using a TextInput. By implementing the onAccepted signal handler, the Todo data is appended to the model. After appending the new Todo, the text property is cleared so that the next Todo can be entered.


Inside the delegate, the data for the index is available by using the property names (title and completed). The title property is directly assigned to the text displayed on each list item. The completed boolean is used to display the item with a strikeout font and a light color.


The Enginio::EnginioModel::setProperty() function is called to update the data in the Enginio backend.


The _synced property can be used to ascertain whether an item has been synced or not. It is always available in the delegate, and may be used, for example, to disable the user interface until syncing has completed.


Finally, a remove button is visible when hovering over an item with the mouse. Removal is implemented by calling EnginioModel::remove() with the row of the item.