[Interest] ListView not showing data until interacted with.

Russell, Matthew MRussell at neptec.com
Tue Apr 25 22:51:09 CEST 2017


Hi,

My QML `ListView` doesn't show my data until I perturb it with the mouse (e.g. just drag it up and down.)  After this the view shows the model without issue.  Is there way to kick this `ListView` into working?

I'm using Qt 5.8 on Linux 14.04.  My model is a subclass of `QAbstractListModel`.  I build it by following the AbstractItemModel<http://doc.qt.io/qt-5/qtquick-models-abstractitemmodel-example.html>.  The main difference is that my list model is a property of an entity, rather than being set with `setContextProperty` in `main.cpp`.

There are a few similar issues on SO, and the Qt forums, about the `ListView`s not updating, but none seem to only have an issue at the start.  Most of them relate to the OP calling `dataChanged` manually instead of `beforeInsertRows()` & `endInsertRows()` - both methods I'm calling (see below.)

My `ListView` is in an item loaded with a `SceneLoader`.

I posted all the relevant code here<https://gist.github.com/kheaactua/13e3943e10a25f3df295148b1d2f1f86>, because I'm a little suspicious of how I use the Layouts on my `ListView` (maybe that's causing it?  Maybe my hierarchy is broken?  I haven't been able to prove that though.)

The most important parts though (code is formatted in the SO style)

ListView:

    ListView {
        anchors.fill: parent
        model: sceneGraph.blobs
        delegate: delegate
    }


BlobModel.cpp:

    auto BlobModel::addBlob(const BlobPointDataPtr& data) -> void
    {
        // ...

        // Each blob has a uuid

        const auto idx = Contains(uuid);
        if (-1 != idx)
        {
            blobs_[idx]->Update(data);
            Q_EMIT dataChanged(createIndex(idx, 0), createIndex(idx, 0));
        }
        else
        {
            beginInsertRows(QModelIndex(), rowCount(), rowCount());
            blobs_ << new Blob{data, id_count_}; id_count_++;
            endInsertRows(); // responsible for the QQmlChangeSet

            Q_EMIT dataChanged(createIndex(rowCount(), 0), createIndex(rowCount(), 0));
        }
    }

Also, on my terminal, I receive the message:

    QObject::connect: Cannot queue arguments of type 'QQmlChangeSet'
    (Make sure 'QQmlChangeSet' is registered using qRegisterMetaType().)

This seems to be emitted by `endInsertRows()`, but I'm not sure why.  In the past the solution has been to register the missing type, e.g. `qRegisterMetaType<QQmlChangeSet*>("QQmlChangeSet");` but this seems not to be a public type with Qt, and because everything mostly works without it, I'm not sure missing that is the exact issue.

(I also cross-posted this question on SO at http://stackoverflow.com/questions/43620606/listview-not-initially-showing-data , just so the code would show better than in an email.)

Thanks for any help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170425/93c4ccaf/attachment.html>


More information about the Interest mailing list