Important: Please read the Qt Code of Conduct -

Immediatly updating data in qml tableView

  • Hello, guys! I need your help.
    I use qml table view for rendering data which I get from video file.
    For this task I have Parser class, from which I call function extractDataWrapper() for file parsing.
    I call extractDataWrapper() from ApplicationWindow by button click
    In general, all looks something like this

    class Parser : public QObject
    Q_INVOKABLE void extractDataWrapper();

    In main.cpp I create object from this class, register types and so on.

    #include "parser.h"
    int main(int argc, char *argv[])    
        QApplication app(argc, argv);
        QQmlApplicationEngine engine;
        Parser parser_;
        qmlRegisterUncreatableType<Parser>("Parser", 1, 0, "Parser", "");
        engine.rootContext()->setContextProperty("Parser", &parser_);
        if (engine.rootObjects().isEmpty()) return -1;
        return app.exec();

    I use my class NoteModel inherited from QAbstractListModel as model.

    class Note {
    // objects for NoteModel 
    class NoteModel : public QAbstractListModel
        ExtractorNoteModel(QObject *parent = 0);
        ~ExtractorNoteModel() override;
        void addNote(const ExtractorNote* note);
        int rowCount(const QModelIndex & parent = QModelIndex()) const override;
        QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
        QHash<int, QByteArray> roleNames() const override;
        QList<Note*> notes_;

    With addNote() I add data to model like this:

    #include "NoteModel"
    void NoteModel::addNote(const Note *note) {
        beginInsertRows(QModelIndex(), rowCount(), rowCount());
        notes_ << const_cast<Note*>(note);

    With call parser_.extractDataWrapper() inside this function I set data to model like this

    #include "parser.h"
    void Parser::extractDataWrapper(){
            NoteModel* ptr;
            ptr->addNote(new Note(/* my arguments */))

    Between calls ptr->addNote(new Note(/* my arguments */)) some time goes by.
    After parser_.extractDataWrapper() finished I get updated table view my main.qml file
    In common interface looks like this
    ![alt text](272e0fa7-89ad-41cb-8575-485a58cee218-image.png image url)
    But view updates all entries only after parser_.extractDataWrapper() is finished.
    The question is:
    Can I update table view immediately after new entry was added to NoteModel, i.e one by one entry
    and if can what I need to do?
    Any help would be helpful.

  • Ok, I've got it. Just need use QThread or std::thread.
    Without another thread interface will be updated only after function finished execution and return control back to renderer engine.
    i.e. need call parser_.extractDataWrapper() in another thread, and all will be ok.

Log in to reply