Displaying my data to QTableWidget
-
I have created a table widget with headers RYOTNUMBER ,PLOTNUMBER and CUTTINGORDERCODE , well my code is
sn "1" SEASONCODE "1920" RYOTNUMBER "INKA010601001004" VILLAGECODE "INKA010601001" OFFICERCODE "MD001 " DATE "2019-01-30" TIME "14:50" OFFICERNAME "Y T VODDAGALLAIA" PLOTNUMBER "123" CUTTINGORDERCODE "0051" GANGLEADERCODE "GNL0001" MODEOFTRANSPORT "Own" CROPTYPE "HSV" COB "2019-06-17" sn "2" SEASONCODE "1920" RYOTNUMBER "INKA010601001004" VILLAGECODE "INKA010601001" OFFICERCODE "MD001 " DATE "2019-01-30" TIME "17:30" OFFICERNAME "Y T VODDAGALLAIA" PLOTNUMBER "421" CUTTINGORDERCODE "009" GANGLEADERCODE "GNL0001" MODEOFTRANSPORT "Company" CROPTYPE "HSV" COB "2019-03-9"where it keeps on going so now my question is I need these RYOTNUMBER ,PLOTNUMBER and CUTTINGORDERCODE three values to be entered in my table. Any help?
Thanks and regards.
-
I have created a table widget with headers RYOTNUMBER ,PLOTNUMBER and CUTTINGORDERCODE , well my code is
sn "1" SEASONCODE "1920" RYOTNUMBER "INKA010601001004" VILLAGECODE "INKA010601001" OFFICERCODE "MD001 " DATE "2019-01-30" TIME "14:50" OFFICERNAME "Y T VODDAGALLAIA" PLOTNUMBER "123" CUTTINGORDERCODE "0051" GANGLEADERCODE "GNL0001" MODEOFTRANSPORT "Own" CROPTYPE "HSV" COB "2019-06-17" sn "2" SEASONCODE "1920" RYOTNUMBER "INKA010601001004" VILLAGECODE "INKA010601001" OFFICERCODE "MD001 " DATE "2019-01-30" TIME "17:30" OFFICERNAME "Y T VODDAGALLAIA" PLOTNUMBER "421" CUTTINGORDERCODE "009" GANGLEADERCODE "GNL0001" MODEOFTRANSPORT "Company" CROPTYPE "HSV" COB "2019-03-9"where it keeps on going so now my question is I need these RYOTNUMBER ,PLOTNUMBER and CUTTINGORDERCODE three values to be entered in my table. Any help?
Thanks and regards.
@Vineela It is shown in the documentation http://doc.qt.io/qt-5/qtablewidget.html
QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg( (row+1)*(column+1))); tableWidget->setItem(row, column, newItem); -
@Vineela It is shown in the documentation http://doc.qt.io/qt-5/qtablewidget.html
QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg( (row+1)*(column+1))); tableWidget->setItem(row, column, newItem);@jsulm well check out this code i know its not correct plz correct me,
QSqlQuery q; q.prepare("SELECT * FROM cuttorderTable WHERE flag = '1' "); q.exec(); while (q.next()) { qDebug() << "Hi thread2"; QString sn = q.value(0).toString(); qDebug() << "sn" << sn; QString i1 = q.value(1).toString(); qDebug() << "SEASONCODE" << i1; QString mn = q.value(2).toString(); qDebug() << "RYOTNUMBER" << mn; QString j = q.value(3).toString(); qDebug() << "VILLAGECODE" << j; QString k = q.value(4).toString(); qDebug() << "OFFICERCODE" << k; QString l = q.value(5).toString(); qDebug() << "DATE" << l; QString m = q.value(6).toString(); qDebug() << "TIME" << m; QString n = q.value(7).toString(); qDebug() << "OFFICERNAME" << n; QString o = q.value(8).toString(); qDebug() << "PLOTNUMBER" << o; QString p = q.value(9).toString(); qDebug() << "CUTTINGORDERCODE" << p; QString t = q.value(10).toString(); qDebug() << "GANGLEADERCODE" << t; QString u = q.value(11).toString(); qDebug() << "TRANSPORTERCODE" << u; QString v = q.value(12).toString(); qDebug() << "MODEOFTRANSPORT" << v; QString w = q.value(13).toString(); qDebug() << "CROPTYPE" << w; QString a = q.value(14).toString(); qDebug() << "COB" << a; QTableWidgetItem *mn1 = new QTableWidgetItem(tr("%1").arg( (0+1)*(0+1))); ui->tableWidget->setItem(0, 0, mn1); QTableWidgetItem *o1 = new QTableWidgetItem(tr("%1").arg( (0+1)*(1+1))); ui->tableWidget->setItem(0, 1, o1); QTableWidgetItem *a1 = new QTableWidgetItem(tr("%1").arg( (0+1)*(2+1))); ui->tableWidget->setItem(0, 2, a1); } -
Slow down, you are overcomplicating massively.
- Replace the
QTableWidgetwith aQTableView - use the code below:
QSqlTableModel* model = new QSqlTableModel(this); model->setTable(QStringLiteral("cuttorderTable")); model->setFilter(QStringLiteral("flag = '1'")); model->select(); ui->tableView->setModel(model);P.S.
qDebug() << "Hi thread2";The ui can only be changed by the ui thread and databases can be used only in the thread that created them so be very careful if you are using multiple threads
- Replace the
-
Slow down, you are overcomplicating massively.
- Replace the
QTableWidgetwith aQTableView - use the code below:
QSqlTableModel* model = new QSqlTableModel(this); model->setTable(QStringLiteral("cuttorderTable")); model->setFilter(QStringLiteral("flag = '1'")); model->select(); ui->tableView->setModel(model);P.S.
qDebug() << "Hi thread2";The ui can only be changed by the ui thread and databases can be used only in the thread that created them so be very careful if you are using multiple threads
- Replace the
-
Slow down, you are overcomplicating massively.
- Replace the
QTableWidgetwith aQTableView - use the code below:
QSqlTableModel* model = new QSqlTableModel(this); model->setTable(QStringLiteral("cuttorderTable")); model->setFilter(QStringLiteral("flag = '1'")); model->select(); ui->tableView->setModel(model);P.S.
qDebug() << "Hi thread2";The ui can only be changed by the ui thread and databases can be used only in the thread that created them so be very careful if you are using multiple threads
- Replace the