qt的tableview实时刷新显示数据

qtableview设置表头:

    model = new QStandardItemModel();
    model->setColumnCount(5);    model->setHeaderData(0,Qt::Horizontal,QString::fromLocal8Bit("EPC"));
    model->setHeaderData(1,Qt::Horizontal,QString::fromLocal8Bit("PC"));
    model->setHeaderData(2,Qt::Horizontal,QString::fromLocal8Bit("Ant"));
    model->setHeaderData(3,Qt::Horizontal,QString::fromLocal8Bit("RSSI"));
    model->setHeaderData(4,Qt::Horizontal,QString::fromLocal8Bit("ReadCount"));
    ui->lst_ReadTag->setModel(model);

添加新数据:

  model->setItem(lst_TagData.count(), 0, new QStandardItem(tag));
        model->setItem(lst_TagData.count(), 1, new QStandardItem(tagData.at(1)));
        model->setItem(lst_TagData.count(), 2, new QStandardItem(tagData.at(2)));
        model->setItem(lst_TagData.count(), 3, new QStandardItem(tagData.at(3)));
        model->setItem(lst_TagData.count(), 4, new QStandardItem("1"));
        ui->lst_ReadTag->setModel(model);
        ui->lst_ReadTag->resizeColumnsToContents();

获取并修改某格数据:

        int readcount = model->data(model->index(tagIndex, 4)).toInt();
        model->setData(model->index(tagIndex, 4), QString::number(++readcount));

多线程的数据显示需链接到主线程进行更新显示数据:

connect(m_pNetWorkModule, SIGNAL(signal_GetTagData(QString)), this, SLOT(GetReadTagOpt(QString)));

你可能感兴趣的:(嵌入式linux,QT多平台)