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. ıt doesnt add list items into table widget
Forum Updated to NodeBB v4.3 + New Features

ıt doesnt add list items into table widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 579 Views 1 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.
  • D Offline
    D Offline
    deleted286
    wrote on last edited by
    #1

    I know, my list is not empy, but it didnt add list items into table

    void MainWindow::tablo_olustur()
    {
       ui->tableWidget->setRowCount(gpsList.size());
    
       for ( int row = 0; row < gpsList.size(); ++row )
       {
           for (int i=0; i<gpsList.size() ; i++ )
           {
               ui->tableWidget->setItem(row, 0, new QTableWidgetItem(gpsList[i]));
           }
    
        }
       qDebug() << gpsList;
    
    }
    
    jsulmJ 1 Reply Last reply
    0
    • D deleted286

      I know, my list is not empy, but it didnt add list items into table

      void MainWindow::tablo_olustur()
      {
         ui->tableWidget->setRowCount(gpsList.size());
      
         for ( int row = 0; row < gpsList.size(); ++row )
         {
             for (int i=0; i<gpsList.size() ; i++ )
             {
                 ui->tableWidget->setItem(row, 0, new QTableWidgetItem(gpsList[i]));
             }
      
          }
         qDebug() << gpsList;
      
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @suslucoder So, what did you try so far to find out what happens? You do not even have debug output (only one)! Please first try to find the issue by yourself. And why do you add up to i items in same row and same column? You will only see the last one...

      for (int i=0; i<gpsList.size() ; i++ )
      {
           ui->tableWidget->setItem(row, 0, new QTableWidgetItem(gpsList[i])); // You put all 0..i gpsList elements in exactly same cell!
      }
      

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

      D 1 Reply Last reply
      2
      • jsulmJ jsulm

        @suslucoder So, what did you try so far to find out what happens? You do not even have debug output (only one)! Please first try to find the issue by yourself. And why do you add up to i items in same row and same column? You will only see the last one...

        for (int i=0; i<gpsList.size() ; i++ )
        {
             ui->tableWidget->setItem(row, 0, new QTableWidgetItem(gpsList[i])); // You put all 0..i gpsList elements in exactly same cell!
        }
        
        D Offline
        D Offline
        deleted286
        wrote on last edited by
        #3

        @jsulm ı tried to do

         ```
        
        ui->tableWidget->setItem(0, 0, new QTableWidgetItem(gpsList[i0]));
        
        but it doesnt work still :(
        jsulmJ 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Why do you have a double loop in the first place ?

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

          1 Reply Last reply
          2
          • D deleted286

            @jsulm ı tried to do

             ```
            
            ui->tableWidget->setItem(0, 0, new QTableWidgetItem(gpsList[i0]));
            
            but it doesnt work still :(
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @suslucoder Can you please explain how you want to put the elements from gpsList into your table? All elements in one row or something else? As @SGaist pointed out iterating over the same list in two nested loops does not make sense...

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

            1 Reply Last reply
            0

            • Login

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