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. Sqlite change Row Value
Forum Updated to NodeBB v4.3 + New Features

Sqlite change Row Value

Scheduled Pinned Locked Moved Unsolved General and Desktop
31 Posts 7 Posters 7.0k Views 3 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
    Aioria
    wrote on 5 Nov 2018, 21:10 last edited by
    #22

    @JonB @jsulm
    Can anyone help me with this last thing?

    void MainWindow::chequedState(int i){
    
        if (ui->listWidget->item(i)->checkState() == Qt::Unchecked)
        {
            QSqlQuery update;
            update.bindValue(":id", i);
            update.prepare("UPDATE students SET faults = faults + 1 WHERE id");
            update.exec();
        }
    
    
    }
    /void MainWindow::saveAssistence()
    {
        int rowCount = ui->listWidget->count();
    
        for (int i = 0; i < rowCount; i++)
        {
            chequedState(i);
        }
    
    
    }
    

    I have this 2 functions and increments in 3 instead in 1 each row.

    Thank you!

    J 1 Reply Last reply 6 Nov 2018, 05:56
    0
    • A Aioria
      5 Nov 2018, 21:10

      @JonB @jsulm
      Can anyone help me with this last thing?

      void MainWindow::chequedState(int i){
      
          if (ui->listWidget->item(i)->checkState() == Qt::Unchecked)
          {
              QSqlQuery update;
              update.bindValue(":id", i);
              update.prepare("UPDATE students SET faults = faults + 1 WHERE id");
              update.exec();
          }
      
      
      }
      /void MainWindow::saveAssistence()
      {
          int rowCount = ui->listWidget->count();
      
          for (int i = 0; i < rowCount; i++)
          {
              chequedState(i);
          }
      
      
      }
      

      I have this 2 functions and increments in 3 instead in 1 each row.

      Thank you!

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 6 Nov 2018, 05:56 last edited by
      #23

      @Aioria said in Sqlite change Row Value:

      UPDATE students SET faults = faults + 1 WHERE id

      please take a closer look at the WHERE part of your update query...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply 6 Nov 2018, 11:56
      2
      • J jsulm
        6 Nov 2018, 05:56

        @Aioria said in Sqlite change Row Value:

        UPDATE students SET faults = faults + 1 WHERE id

        please take a closer look at the WHERE part of your update query...

        A Offline
        A Offline
        Aioria
        wrote on 6 Nov 2018, 11:56 last edited by
        #24

        @jsulm
        I tried to put =: id but don't do nothing. I think that the problem is in the for. Maybe another way to do it. This increment all the rows in the quantity of rows that the table have...

        J 1 Reply Last reply 6 Nov 2018, 12:11
        0
        • A Aioria
          6 Nov 2018, 11:56

          @jsulm
          I tried to put =: id but don't do nothing. I think that the problem is in the for. Maybe another way to do it. This increment all the rows in the quantity of rows that the table have...

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 6 Nov 2018, 12:11 last edited by
          #25

          @Aioria Are you sure the row number in the list widget is the correct ID in the table?!

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply 7 Nov 2018, 17:57
          0
          • J jsulm
            6 Nov 2018, 12:11

            @Aioria Are you sure the row number in the list widget is the correct ID in the table?!

            A Offline
            A Offline
            Aioria
            wrote on 7 Nov 2018, 17:57 last edited by
            #26

            @jsulm I think with the :id, i , i put the value of i in the id.
            How can i check that and how can i do to make an union between the list and the table?

            CreateStudentTable();
                int row = ShowData();
                setWindowTitle(QString ("Asistencia"));
                QList<QString> items;
                for (int i = 0; i<row;i++)
                {
                    items.append("" + QString::number(i));
                }
                QListIterator <QString> itr(items);
                while(itr.hasNext())
                {
                    QListWidgetItem *item = new QListWidgetItem(itr.next());
                    item->setCheckState(Qt::Unchecked);
                    ui->listWidget->addItem(item);
                }
            
                ShowData();
            

            This is the code that creates the list with the checkbox

            P J 2 Replies Last reply 7 Nov 2018, 18:36
            0
            • A Aioria
              7 Nov 2018, 17:57

              @jsulm I think with the :id, i , i put the value of i in the id.
              How can i check that and how can i do to make an union between the list and the table?

              CreateStudentTable();
                  int row = ShowData();
                  setWindowTitle(QString ("Asistencia"));
                  QList<QString> items;
                  for (int i = 0; i<row;i++)
                  {
                      items.append("" + QString::number(i));
                  }
                  QListIterator <QString> itr(items);
                  while(itr.hasNext())
                  {
                      QListWidgetItem *item = new QListWidgetItem(itr.next());
                      item->setCheckState(Qt::Unchecked);
                      ui->listWidget->addItem(item);
                  }
              
                  ShowData();
              

              This is the code that creates the list with the checkbox

              P Offline
              P Offline
              Pablo J. Rogina
              wrote on 7 Nov 2018, 18:36 last edited by
              #27

              @Aioria please try to not double post. I know, that post is Spanish but you're trying to solve the same issue :-)

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              2
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 7 Nov 2018, 20:53 last edited by
                #28

                @Pablo-J-Rogina it's usually the only case where double posting is allowed since it's in the poster native language and therefor might get an answer that's easier to understand.

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

                P 1 Reply Last reply 7 Nov 2018, 20:55
                1
                • S SGaist
                  7 Nov 2018, 20:53

                  @Pablo-J-Rogina it's usually the only case where double posting is allowed since it's in the poster native language and therefor might get an answer that's easier to understand.

                  P Offline
                  P Offline
                  Pablo J. Rogina
                  wrote on 7 Nov 2018, 20:55 last edited by
                  #29

                  @SGaist got it, it's learnt since now on forward. Thank you for the clarification.

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • A Aioria
                    7 Nov 2018, 17:57

                    @jsulm I think with the :id, i , i put the value of i in the id.
                    How can i check that and how can i do to make an union between the list and the table?

                    CreateStudentTable();
                        int row = ShowData();
                        setWindowTitle(QString ("Asistencia"));
                        QList<QString> items;
                        for (int i = 0; i<row;i++)
                        {
                            items.append("" + QString::number(i));
                        }
                        QListIterator <QString> itr(items);
                        while(itr.hasNext())
                        {
                            QListWidgetItem *item = new QListWidgetItem(itr.next());
                            item->setCheckState(Qt::Unchecked);
                            ui->listWidget->addItem(item);
                        }
                    
                        ShowData();
                    

                    This is the code that creates the list with the checkbox

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 8 Nov 2018, 05:19 last edited by jsulm 11 Aug 2018, 05:20
                    #30

                    @Aioria said in Sqlite change Row Value:

                    I think with the :id, i , i put the value of i in the id

                    Yes, you do and this is a bad idea. The id of an item in the database should not be its row number in some widget in your UI! What happens, for example, if you order/sort the items differently? Then suddenly all your IDs are wrong.
                    You can use http://doc.qt.io/qt-5/qlistwidgetitem.html#setData to set the database ID in your items and then get it using http://doc.qt.io/qt-5/qlistwidgetitem.html#data

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    A 1 Reply Last reply 8 Nov 2018, 13:46
                    1
                    • J jsulm
                      8 Nov 2018, 05:19

                      @Aioria said in Sqlite change Row Value:

                      I think with the :id, i , i put the value of i in the id

                      Yes, you do and this is a bad idea. The id of an item in the database should not be its row number in some widget in your UI! What happens, for example, if you order/sort the items differently? Then suddenly all your IDs are wrong.
                      You can use http://doc.qt.io/qt-5/qlistwidgetitem.html#setData to set the database ID in your items and then get it using http://doc.qt.io/qt-5/qlistwidgetitem.html#data

                      A Offline
                      A Offline
                      Aioria
                      wrote on 8 Nov 2018, 13:46 last edited by
                      #31

                      @jsulm
                      Thank you! I will try to do that instead the bindvalue!

                      1 Reply Last reply
                      0

                      31/31

                      8 Nov 2018, 13:46

                      • Login

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