Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem about subclassing tableModel
Servers for Qt installer are currently down

Problem about subclassing tableModel

Scheduled Pinned Locked Moved General and Desktop
tablemodel
2 Posts 2 Posters 603 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Y.Circle
    wrote on 22 Sept 2015, 09:36 last edited by
    #1

    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
    {
        cSocket.sendData(ModelType,1);
        waitFlag=1;
        while(waitFlag);
        return rowNumber;
    }
    

    And the waitFlag is changed after receiving data from server;

    void MyTableModel::recPacket1(qint64 type,qint64 rowC)
    {
        if(ModelType!=type) return;
        rowNumber=rowC;
        qDebug()<<"ModelType:"<<type<<"RowCount:"<<rowC;
        waitFlag=0;
    }
    

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

        ui->cagroListTableView->setModel(cagroListModel);
    

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 Sept 2015, 20:19 last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      22 Sept 2015, 09:36

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved