QSqlTableModel performance problem

  • Hi,
    I use a QSqlTableModel to log all application activity: my QTableView is connected with a QSqlTableModel from MySQL table
    I have a performance problem with it when I Have more than 3000 logs line
    this is how I do:

    QSqlDatabase* pdatabase = CDatabase::GetInstance();
    m_model = new QSqlTableModel(NULL, *pdatabase);
    m_model->setHeaderData(0, Qt::Horizontal, "ID");
    m_model->setHeaderData(1, Qt::Horizontal, "Type");
    m_model->setHeaderData(2, Qt::Horizontal, "Date");
    m_model->setHeaderData(3, Qt::Horizontal, "Time");
    m_model->setHeaderData(4, Qt::Horizontal, "Text");

    then I connect the model to the QTableView

    ui->tableViewLog->sortByColumn(0, Qt::DescendingOrder);

    And the function that add a log line:
    void ClogManager::addLogLine(QString logLine, QString logType)

    QModelIndex num = m_model->index(m_model->rowCount()-1, LOGMODEL_NUM);
    QModelIndex type = m_model->index(m_model->rowCount()-1, LOGMODEL_TYPE);
    QModelIndex date = m_model->index(m_model->rowCount()-1, LOGMODEL_DATE);
    QModelIndex time = m_model->index(m_model->rowCount()-1, LOGMODEL_TIME);
    QModelIndex text = m_model->index(m_model->rowCount()-1, LOGMODEL_TEXT);
    m_model->setData(num, m_model->rowCount());
    m_model->setData(type, logType);
    m_model->setData(date, QDateTime::currentDateTime().toString("yy/MM/dd"));
    m_model->setData(time, QTime::currentTime().toString("HH:mm"));
    m_model->setData(text, logLine);
    //emit m_model->dataChanged(num, text);


    m_model->select() takes more and more time, how can I refresh in my QTableView only the line added in my log
    I tryed m_model->selectRow but it dont works, it only add a line with a "!"
    do you have any idea?
    thank you

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.