Qt World Summit: Submit your Presentation

QTreeView & QStandardItemModel.

  • Hi Forum,

    I have a database that has tables representing Jobs and the Tasks associated with them.

    My goal is to display a QTreeView with a Job and then each task as a child below that; as well as a QTreeView with task categories and the tasks that fall into that category as children below that (in a different view).

    Currently, I am reading all the jobs and their tasks then constructing a QStandardItemModel and setting it to the QTreeView. This obviously only displays a copy of what is in the database and if any changes are made to the data elsewhere they aren't shown until the next manual update.
    I also want to display this model in a number of different views.

    What I have so far:
    QStringList jobs = api->jobs();

    QStringList headerLabels;
    headerLabels << "Date" << "UUID" << "Assigned" << "Due Date" << "Status";
    foreach(const QString& job, jobs) {
        QList <QStandardItem *> jobItem;
        jobItem << new QStandardItem(api->jobTitle(job));
        QStringList tasks = api->tasksByJob(job);
        foreach(const QString& task, tasks) {
            QList<QStandardItem*> items;
            items << new QStandardItem(api->taskTitle(task));
            items << new QStandardItem(task);
            items << new QStandardItem(api->taskAssignee(task));
            items << new QStandardItem(api->taskDue(task));
            items << new QStandardItem(api->taskStatus(task));
            jobItem.at(0)->appendRow(items); // append child items to top-level item


    What should I be doing so that I am working directing with the data and not a copy of it?
    So far I haven't been able to get a model into a QTreeView other than by manufacturing a QStandardItemModel.

    Edit: Should I be using an QAbstractProxyModel?

Log in to reply