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. Issue with Qt Table widget
Forum Updated to NodeBB v4.3 + New Features

Issue with Qt Table widget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 219 Views
  • 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.
  • H Offline
    H Offline
    http_edo13
    wrote on 3 Sept 2020, 09:17 last edited by http_edo13 9 Mar 2020, 09:51
    #1

    0

    I have a table that shows me the articles. The problem is that when I go to insert a new article and go back to the home for the first 2 items it doesn't give me problems, from the third time that I inserts article, the table show the second product again without the while loop inserting it.

    The for loop performs a hard erase every time I go back to the home, as seen also from the console.

    Where am I wrong? can anyone help me?

    void magazzino::populateTable(){
    
        std::cout<<"number of row"<<view->rowCount()<<std::endl;
        int righe = view->rowCount();
        for(int k=0; k<righe;k++){
            std::cout<<"for time"<<k<<std::endl;
            view->removeRow(k);
        }
    
        Cont::iteratore* iter = new Cont::iteratore(contenitore->getFirst());
        int i = 0;
        while(iter->punt){
            std::cout<<"while time"<<i<<std::endl;
    
            QString cod = QString::number(iter->punt->getInfo().getCodice());
            QTableWidgetItem* codice = new QTableWidgetItem(cod);
            QString mar = QString::fromStdString(iter->punt->getInfo().getMarca());
            QTableWidgetItem* marca = new QTableWidgetItem(mar);
            QString mod = QString::fromStdString(iter->punt->getInfo().getModello());
            QTableWidgetItem* modello = new QTableWidgetItem(mod);
            QString pr = QString::number(iter->punt->getInfo().getPrezzo());
            pr.append(" €");
            QTableWidgetItem* prezzo = new QTableWidgetItem(pr);
    
            //QString at = QString::number(iter->punt->getInfo().getAltezza());
            //QTableWidgetItem* altezzaTacco = new QTableWidgetItem(at);
    
            view->insertRow(i);
            view->setItem(i, 0, codice);
            view->setItem(i, 1, marca);
            view->setItem(i, 2, modello);
            view->setItem(i, 3, prezzo);
    
            iter->punt = iter->punt->next;
            i++;
        }
    }
    

    alt text
    alt text

    J 1 Reply Last reply 3 Sept 2020, 09:26
    0
    • H http_edo13
      3 Sept 2020, 09:17

      0

      I have a table that shows me the articles. The problem is that when I go to insert a new article and go back to the home for the first 2 items it doesn't give me problems, from the third time that I inserts article, the table show the second product again without the while loop inserting it.

      The for loop performs a hard erase every time I go back to the home, as seen also from the console.

      Where am I wrong? can anyone help me?

      void magazzino::populateTable(){
      
          std::cout<<"number of row"<<view->rowCount()<<std::endl;
          int righe = view->rowCount();
          for(int k=0; k<righe;k++){
              std::cout<<"for time"<<k<<std::endl;
              view->removeRow(k);
          }
      
          Cont::iteratore* iter = new Cont::iteratore(contenitore->getFirst());
          int i = 0;
          while(iter->punt){
              std::cout<<"while time"<<i<<std::endl;
      
              QString cod = QString::number(iter->punt->getInfo().getCodice());
              QTableWidgetItem* codice = new QTableWidgetItem(cod);
              QString mar = QString::fromStdString(iter->punt->getInfo().getMarca());
              QTableWidgetItem* marca = new QTableWidgetItem(mar);
              QString mod = QString::fromStdString(iter->punt->getInfo().getModello());
              QTableWidgetItem* modello = new QTableWidgetItem(mod);
              QString pr = QString::number(iter->punt->getInfo().getPrezzo());
              pr.append(" €");
              QTableWidgetItem* prezzo = new QTableWidgetItem(pr);
      
              //QString at = QString::number(iter->punt->getInfo().getAltezza());
              //QTableWidgetItem* altezzaTacco = new QTableWidgetItem(at);
      
              view->insertRow(i);
              view->setItem(i, 0, codice);
              view->setItem(i, 1, marca);
              view->setItem(i, 2, modello);
              view->setItem(i, 3, prezzo);
      
              iter->punt = iter->punt->next;
              i++;
          }
      }
      

      alt text
      alt text

      J Online
      J Online
      JonB
      wrote on 3 Sept 2020, 09:26 last edited by JonB 9 Mar 2020, 11:13
      #2

      @http_edo13
      Please post the actual text of code, not screenshots, so that people can copy & paste.

      int righe = view->rowCount();
      for (int k = 0; k < righe; k++)
          view->removeRow(k);
      

      Each time through the loop, print out k and print out view->rowCount() again. Do you see what is happening? Your code is not right, rowCount() is being decremented (and hence changing) as each row is removed.

      If you want to remove all rows, you either want to repeatedly remove row 0, or count downward from view->rowCount() - 1, or why not do it without a loop via setRowCount(0)?

      1 Reply Last reply
      1
      • H Offline
        H Offline
        http_edo13
        wrote on 3 Sept 2020, 10:03 last edited by
        #3

        With setRowCount(0) I solved the problem. Thank you very much!! @JonB

        1 Reply Last reply
        0

        1/3

        3 Sept 2020, 09:17

        • Login

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