One question about store data in database



  • 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 )


  • Lifetime Qt Champion

    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.



  • @SGaist Thanks
    I need store data of QString name in table.
    How can i do?


  • Lifetime Qt Champion

    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 )


  • Qt Champions 2016

    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;


Log in to reply
 

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