Show SQLITE data in a QTableWidget



  • hello i have a problem. i am keeping data in a table of my sqlite database with a different id ....but when i show the data in a qtablewidget, the data appear in a continuos order ....
    how i can show exactly the data of the table of my database on my qtablewidget................

    for example i save data in a table in the row 0, row 3 and row 5 of my sqlite database
    when i show these data in a qtablewidget these appear in the row 0 row1 and row 2
    i need that the data of my sqlite database will be in the same position in my qtablewidget?????

    i am using this code to show data from my database to my qtablewidget

    QString tabla;
    tabla.append("SELECT * FROM contactos");

    QSqlQuery mostrar;
    mostrar.prepare(tabla);

    if(mostrar.exec())
    qDebug() << "ok mostarr ";
    else
    qDebug() << "ERROR"<< mostrar.lastError();

    int fila=0;
    // ui->tabla_gui->setRowCount(0);
    while (mostrar.next())
    {
    ui->tabla_gui->setItem(fila,0,new QTableWidgetItem(mostrar.value(1).toString()));
    ui->tabla_gui->setItem(fila,1,new QTableWidgetItem(mostrar.value(2).toString()));
    fila ++;
    }



  • @paul_espinosa said:

    for example i save data in a table in the row 0, row 3 and row 5 of my sqlite database

    What does it mean?
    you have only contiguous rows.

    The easiest way to show table contents in a Widget is to use QTableView and QSqlTableModel


Log in to reply
 

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