how to save Qtablewidgte table to a row in sqlite
-
i have Qtablewidgte inserted by the user and i want to save it in a Sqlite row
separated by ';' -
Hi
Well you just loop the row/cols and take data.
https://forum.qt.io/topic/23764/save-qtablewidget/10 -
@mrjj
i use CellWidget "Qspinbox"
and the function that you mentioned it is not working to get the values of the spinbox -
@davidlabib
well you must get the text from the widget then.
http://doc.qt.io/qt-5/qspinbox.html#cleanText-prop -
@mrjj
i know how to get the value of the spinbox the probilm is there is alot of spinboxes
in each row the user inserts it will make new spinbox -
i know how to get the value of the spinbox the probilm is there is alot of spinboxes
- Would you like to reduce the number of used input control objects for your selected data set anyhow?
- How do you think about restructure the shown source code example a bit more?
-
void Invoices::on_barcodeIN_returnPressed() { QSqlQuery qry; qry.exec("SELECT NAME, UNITPRICE FROM DRUGS WHERE BARCODE='"+ui->barcodeIN->text()+"'"); //qry.exec("SELECT NAME, UNITPRICE FROM DRUGS WHERE\""+ui->barcodeIN->text()+"\""); if(qry.next()) { QString name = qry.value(0).toString(); QString unitprice = qry.value(1).toString(); float unitpriceint = qry.value(1).toFloat(); int x = ui->tableTW->rowCount(); ui->tableTW->setRowCount(x); ui->tableTW->insertRow(x); QLabel *drugNameLB = new QLabel(name); QSpinBox *quantitySB = new QSpinBox(); QSpinBox *saleIN = new QSpinBox; saleIN->setMinimum(0); saleIN->setMaximum(100); QDateEdit *expireDE = new QDateEdit(); QLabel *pharPriceLB = new QLabel(unitprice+" LE"); QLabel *pubpriceLB = new QLabel(unitprice+" LE"); float yy = unitpriceint - unitpriceint*(saleIN->value()/100); pharPriceLB->setText(QString::number(yy) + " LE"); ui->tableTW->setCellWidget(x,0, drugNameLB); ui->tableTW->setCellWidget(x,1, quantitySB); ui->tableTW->setCellWidget(x,2, saleIN); ui->tableTW->setCellWidget(x,3, expireDE); ui->tableTW->setCellWidget(x,4, pharPriceLB); ui->tableTW->setCellWidget(x,5, pubpriceLB); QObject::connect(saleIN, SIGNAL(valueChanged(int)), this, SLOT(tee(int))); ui->barcodeIN->clear(); } }
what i want is to convert something like that
to something like that
saving the table in one row separated by ';'
but the problim is that i use cellwidget
i don't know how to get the value of spinbox in specific row -
Hi,
QTableWidget::cellWidget is likely what you are looking for.
-
can you write me an example of how can i get the value of the spinbox in a variable
-
Something along the lines of:
QSpinBox *spinBox = qobject_cast<QSpinBox *>(myTableWidget->cellWidget(rowNumber, columnNumber); if (!spinBox) { qDebug() << "Wrong type of cell widget"; return; } int cellValue = spinBox->value();
-
qry.exec("SELECT NAME, UNITPRICE FROM DRUGS WHERE BARCODE='"+ui->barcodeIN->text()+"'");
I suggest to use a prepared query instead of constructing the selection in a questionable way.
ui->tableTW->setRowCount(x);
- I guess that it will help to use a reference variable for the relevant table.
- How do you think about to work with a specific class for the records?
- Could it be that the use of the class “QTableView” would be more appropriate than “QTableWidget” (together with a customised data model)?
saving the table in one row separated by ';'
- Do you really need to concatenate selected values into an enumeration for each field?
- Can it be nicer to keep the filtered records separate?