Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Show SQLITE data in a QTableWidget
Forum Updated to NodeBB v4.3 + New Features

Show SQLITE data in a QTableWidget

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paul_espinosa
    wrote on last edited by
    #1

    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 ++;
    }

    M 1 Reply Last reply
    0
    • P paul_espinosa

      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 ++;
      }

      M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      @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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved