MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

SparqlListModel

Provides a QML binding for QSparqlQueryModel.

    import QtSparql 1.0

Properties

Methods

Property Documentation

Required properties are query and connection.

query : string

Set the QSparqlQuery::SelectStatment to be used to populate the model

connection : SparqlConnection

Set the SparqlConnection to be used for the model.

status : enumeration read-only

Specifies the model status, which can be one of the following:

  • Null - Model has not been set.
  • Ready - Model is ready, and populated with results.
  • Loading - Model is executing the query.
  • Error - There was an error with the query or connection.

The status can be monitored using the statusChanged() signal.

count : int read-only

Returns the number of rows in the model. The countChanged() signal can be used to notify of any insertions or deletions.

Method Documentation

variant get (int i)

Returns the result from row i. See Detailed Description for usage.

void reload ()

Executes the query again. Useful if you wish to periodically check for new results.

string errorString ()

Returns a string description of the last error that occurred if status is SparqlListModel::Error.

Detailed Description

The SparqlListModel binding allows for SPARQL queries to be used as a ListView model. The binding requires a SparqlConnection and a query to be set, E.g :

    ListView {
        id: contactView
        model: SparqlListModel {
                    id:resultList
                    connection: SparqlConnection { driver:"QTRACKER_DIRECT" }
                    query: "select ?u ?firstName ?secondName"+
                           "{ ?u a nco:PersonContact;"+
                           "nco:nameGiven ?firstName;"+
                           "nco:nameFamily ?secondName .}"
                }
        delegate: Item { Text { text: "firstname = "+firstName+", secondname = "+secondName } }
    }

The delegates property names are extracted from the query, see the section "Using Results" in SparqlConnection for more information on this.

If you intend to use the SparqlConnection for other queries, it may be more convenient to declare it as a property, E.g :

    property SparqlConnection sparqlConnection : SparqlConnection {
                                                    driver: "QTRACKER_DIRECT"
                                                 }

    ListView {
        model: SparqlListModel {
                connection: sparqlConnection
                ...
               }
    }

The count property can be used to return the number of rows in the model, and to be notified of insertions/deletions by connecting to the countChanged() signal, E.g :

    SparqlListModel {
        onCountChanged : someFunction()
        ...
    }

To return result information for a specific row in the model, the get function can be used, E.g :

    SparqlListModel {
        id:resultList
        ...
    }

    function getRow(row)
    {
        var result = getRow(row)
        for (var property in result) {
            console.log("Property name = "+property)
            console.log("Property value = "+result[property])
        }
    }

Copyright (C) 2010-2011 Nokia Corporation and/or its subsidiary(-ies).
Commercial Qt/LGPL 2.1 with Nokia exception/GPL 3.0
MeeGo 1.2 Harmattan API