Important: Please read the Qt Code of Conduct -

Problem about subclassing tableModel

  • Hi ALL,
    I use qt 4.8.4.
    I subclass QAbstractTableModel and get data from server using Tcp.I get data in rowCount() and data().

    int MyTableModel::rowCount(const QModelIndex &parent)const
        return rowNumber;

    And the waitFlag is changed after receiving data from server;

    void MyTableModel::recPacket1(qint64 type,qint64 rowC)
        if(ModelType!=type) return;

    But the setModel() block the process.In this.


    I only received one packet on server.But Server send data to client,and client can't process it because setModel blocks(I think).
    Who have code that includes getting data from server in rowCount()?Or how to change this code?What reason causes the problem?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Your while loop is blocking everything. You should rather implement this asynchronously. So set rowNumber to 0 at the beginning and when you get your data and update the model then you can trigger the appropriate signals that will tell the views to refresh themselves so that rowCount and friends will be called with the newly arrived values.

    Hope it helps

Log in to reply