Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. One question about store data in database
Forum Updated to NodeBB v4.3 + New Features

One question about store data in database

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.3k Views 2 Watching
  • 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 Offline
    A Offline
    Armin
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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
      1
      • SGaistS 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.

        A Offline
        A Offline
        Armin
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          1
          • SGaistS SGaist

            What table would that be ?

            A Offline
            A Offline
            Armin
            wrote on last edited by
            #5

            @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
            0
            • A Offline
              A Offline
              Armin
              wrote on last edited by
              #6

              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
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                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
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved