Data storage
Many apps that you create will need to manipulate data in some way. A contacts list app might need to load existing contacts from a data file and save new contacts in the file. A sports app might track team statistics in a data file and update these statistics after each game.
The Cascades framework uses a modular approach to store, access, and display data in your apps. This approach makes it easy for you to store different types of data, organize and model the data in different ways, and display the data with different visual styles.
The following diagram illustrates the different components that interact when you manipulate data in your app:
External data
This component represents the raw data for your app. The data could be a list of contact entries, a set of financial records, or a group of game objects. You can access data that you package with your app, but you can also create new data dynamically as your app runs. The format of this data can vary depending on your needs, and Cascades provides classes that help you manage three common data formats: JSON, SQL, and XML.
Data access
This component lets you access the external data and manipulate it in your app. You can load data files, create new files and save data in them, and handle any errors that might occur during these operations. Then, you can add the data to a data model to organize it before it's displayed. You can use the JsonDataAccess, SqlDataAccess, and XmlDataAccess classes to load and save data in JSON, SQL, and XML format, respectively. You can also access SQL data asynchronously using an SqlConnection. Supporting classes, such as DataAccessError, give you more information about errors so you can handle them appropriately.
Data source
This component is designed specifically as an easy-to-use adapter in QML between external data and UI components. You can use the DataSource class to declare the properties of the external data that you want to access. This data can be SQL, JSON, or XML data that's stored locally, or it can be JSON or XML data feeds that are accessed remotely. You can also use the DataSource class to control when and where the data is loaded.
Data model
This component lets you organize and sort your data, and then provide the data to a list view to display it. For example, you can use a GroupDataModel to sort a list of employees by last name or employee number. Then, you can associate this data model with a list view, and your data is organized and displayed in the way you specified.
To learn more about data models, see Data models.
List view
This component determines how the data from the data model is most often displayed in your app. Each entry in the data model becomes an item in the list, and you can specify how each item should appear visually. You might represent each item using a simple Label, or you might represent each item using multiple controls that you define yourself. A ListView lets you handle all visual aspects of the list, and is separate from the data and the data model that's used to provide the data to display.
To learn more about list views, see List view.
About the file system
The data files that you work with in your apps are stored in the file system on the device. Different file system locations have different permissions; in some areas, you can create new files to store your app data, while in others, you can only load data from existing files. If you want to access your data files using the method that works best for you, you need to understand where your data files are located in the file system.
Data files that you package with your app (when you compile the app) are located in the assets folder in the file system. Your app has read-only access to this folder, which means that you can load data from files in this location, but you can't save new data in these files. When you create new data files dynamically while your app is running, they are stored in the data folder. Your app has full read-write access to this folder, so you can load and save data using files in this location.
To learn more about the file system, see File system access for apps.
About Qt data access APIs
The data access classes that are described in the sections below make it easier to get external data into a form that's suitable for display in Cascades UI components. In most cases, these classes are based on the underlying Qt APIs, which have many useful features and can also be used directly in your apps. These APIs include QtNetwork, QtSql, QtXml, and others.
Last modified: 2013-06-12