One question about store data in database
Solved
General and Desktop
-
Hi
see this code :void MainWindow::on_pushButton_2_clicked() { QString name = ui->textEdit->toPlainText(); QTableWidgetItem *itemobj = table->item(rowfirstlastname , 1); itemobj->setText(name); QString make = ui->comboBox->currentText(); ui->label_7->setText(make); }
If assume rowfirstlastname = 1 , name to be store in table database ? like ( row 1 and column 1 )
-
Hi,
Your question is not clear at all. Can you maybe rephrase it ?
Note that from your code, there's not database involved at all.
-
Hi,
Your question is not clear at all. Can you maybe rephrase it ?
Note that from your code, there's not database involved at all.
-
What table would that be ?
-
@SGaist Thanks
Check this code :
class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); int row=1; int clm=7; int rowfirstlastname = 1; QTableWidget *table = new QTableWidget (row,clm); private slots: void on_pushButton_2_clicked(); private: Ui::MainWindow *ui; };
-
I changed my code :
void MainWindow::on_pushButton_2_clicked() { QString name = ui->textEdit->toPlainText(); QTableWidgetItem *itemobj; itemobj->setText(name); table->setItem(rowfirstlastname , 1 , itemobj ); QString make = ui->comboBox->currentText(); }
and my program will crash ( has stopping work )
-
Hi
Your approach is ok but you forget to allocte the actual item.
QTableWidgetItem *itemobj; << just a pointer, it means can point to. Not IS an item.
must be
QTableWidgetItem *itemobj= new QTableWidgetItem;