[Qt-interest] periodically adding rows to table model

linux newbie linux.newbie79 at gmail.com
Tue Sep 28 06:25:38 CEST 2010


Hi,

I my tableModel which is inherited from QAbstractTableModel, I like to
add new row for every 2secs. I set the QTimer in the constructor and
it is calling "addRow" slot. What steps do I need to follow in
"addRow" slot, in order to create new row and displaying that row in
TableView.

ClientModel::ClientModel(QStringList &string, QObject *parent)
    :QAbstractTableModel(parent)
{
    list = new QStringList(string);
    for (int i = 0; i < list->count(); ++i)
    {
        selectionList.append(false);
    }

    QTimer *timer = new QTimer(this);
    timer->setInterval(2000);
    timer->start();
    connect (timer, SIGNAL(timeout()), this, SLOT(addRow()));

}

void ClientModel::addRow()
{

}


int main (int argc, char *argv[])
{
    QApplication app(argc, argv);

    QTableView table;
    QStringList list;

    list << "a" << "b";

    ClientModel model(list);

    table.setModel(&model);

    table.show();
    return app.exec();
}



More information about the Qt-interest-old mailing list