Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved One question about store data in database

    General and Desktop
    3
    7
    953
    Loading More Posts
    • 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.
    • A
      Armin last edited by

      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 )

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by SGaist

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply Reply Quote 1
        • A
          Armin @SGaist last edited by

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

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            What table would that be ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply Reply Quote 1
            • A
              Armin @SGaist last edited by

              @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;
              };
              
              1 Reply Last reply Reply Quote 0
              • A
                Armin last edited by

                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 )

                1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion last edited by mrjj

                  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;

                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post