Important: Please read the Qt Code of Conduct -

InsertRecord performance in QSqlTableModel.

  • Dear all,

    @if (
    while (!file.atEnd()){
    QString str = file.readLine();
    QStringList strList = str.split("\t"); //parsing tab separated file
    QSqlTableModel.insertRecord(0,makeRecord(strList)); //makeRecord returns QSqlRecord

    That cause serious performance problem. It takes 1 min to parse about 20K lines of file. What's wrong with that code?


  • No idea. Profile your program, switch to the manual submit strategy and call submitAll, consider using QSqlQuery inside ONE transaction, etc.

  • Thanks for advice.

    I already set manual submit. It just to add data to table & manual submitAll later.

    I'll try with QSqlQuery to source Table..

  • @peppe

    I can't get it, QSqlQuery inside ONE transaction is worsen than insertion of table row...

    How can I do that?

  • Where does the profiler say most of the time is being spent?

    Try using QSqlQuery directly rather than via the table model.

Log in to reply