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. QTableWidget Operations over columns
Forum Updated to NodeBB v4.3 + New Features

QTableWidget Operations over columns

Scheduled Pinned Locked Moved General and Desktop
28 Posts 6 Posters 7.5k 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.
  • Chris KawaC Online
    Chris KawaC Online
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by Chris Kawa
    #2

    Sure, here you go:

    connect(&tableWidget, &QTableWidget::itemChanged, &tableWidget, [](QTableWidgetItem* item)
    {
        if (item->column() == 0 || item->column() == 1)
        {
            auto other_item  = item->tableWidget()->item(item->row(), (item->column() + 1)%2);
            auto result_item = item->tableWidget()->item(item->row(), 2);
    
            int val1 = item->data(Qt::DisplayRole).toInt();
            int val2 = other_item->data(Qt::DisplayRole).toInt();
    
            result_item->setData(Qt::DisplayRole, val1 * val2);
        }
    });
    

    Make sure you add necessary error checking (eg. are the values numbers and things like that) and make the 3rd column read only.
    I left that out as an exercise ;)

    AbderaoufA 2 Replies Last reply
    4
    • Chris KawaC Chris Kawa

      Sure, here you go:

      connect(&tableWidget, &QTableWidget::itemChanged, &tableWidget, [](QTableWidgetItem* item)
      {
          if (item->column() == 0 || item->column() == 1)
          {
              auto other_item  = item->tableWidget()->item(item->row(), (item->column() + 1)%2);
              auto result_item = item->tableWidget()->item(item->row(), 2);
      
              int val1 = item->data(Qt::DisplayRole).toInt();
              int val2 = other_item->data(Qt::DisplayRole).toInt();
      
              result_item->setData(Qt::DisplayRole, val1 * val2);
          }
      });
      

      Make sure you add necessary error checking (eg. are the values numbers and things like that) and make the 3rd column read only.
      I left that out as an exercise ;)

      AbderaoufA Offline
      AbderaoufA Offline
      Abderaouf
      wrote on last edited by
      #3

      @Chris-Kawa
      Thas was a hard exercice. I think this is a signal, I don t see the slot though!! I tried to implement that and I get the following error message:

      E:\Computing\Qt Designer\cfadvisor.cpp:191: erreur : no matching function for call to 'CFAdvisor::connect(QTableWidget**, void (QTableWidget::)(QTableWidgetItem), QTableWidget**, CFAdvisor::setupTableItems()::<lambda(QTableWidgetItem*)>)'
      });
      ^
      Thanks

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

        Hi,

        From the look of your error, you are passing the address of the pointer to your QTableWidget item object. Remove the & before it and your should be good to go.

        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
        • Chris KawaC Chris Kawa

          Sure, here you go:

          connect(&tableWidget, &QTableWidget::itemChanged, &tableWidget, [](QTableWidgetItem* item)
          {
              if (item->column() == 0 || item->column() == 1)
              {
                  auto other_item  = item->tableWidget()->item(item->row(), (item->column() + 1)%2);
                  auto result_item = item->tableWidget()->item(item->row(), 2);
          
                  int val1 = item->data(Qt::DisplayRole).toInt();
                  int val2 = other_item->data(Qt::DisplayRole).toInt();
          
                  result_item->setData(Qt::DisplayRole, val1 * val2);
              }
          });
          

          Make sure you add necessary error checking (eg. are the values numbers and things like that) and make the 3rd column read only.
          I left that out as an exercise ;)

          AbderaoufA Offline
          AbderaoufA Offline
          Abderaouf
          wrote on last edited by
          #5

          @Chris-Kawa
          Sir; I got this code; there's no error message and the window pops up but the column 3 does not calculate the result value. Please advise.

          ui(new Ui::CFAdvisor)
          {
          ui->setupUi(this);

          ui->m_ptable_ConvDesign->setItem(0, 0, new QTableWidgetItem("Pre-PAD"));
          ui->m_ptable_ConvDesign->setItem(1, 0, new QTableWidgetItem ("PAD"));
          
              for (int row = 2; row < ui->m_ptable_ConvDesign->rowCount()-9; ++row)
              {
                  for (int column = 1; column < ui->m_ptable_ConvDesign->columnCount(); ++column)
                  {
                   ui->m_ptable_ConvDesign->setItem(row, 0, new QTableWidgetItem ("SLF"));
                  }
              }
          ui->m_ptable_ConvDesign->setItem(10, 0, new QTableWidgetItem ("Flush"));
          
          for (int row = 0; row < ui->m_ptable_ConvDesign->rowCount(); ++row)
          {
              for (int column = 0; column < ui->m_ptable_ConvDesign->columnCount(); ++column)
              {
                  connect(m_ptable_ConvDesign, &QTableWidget::itemChanged, m_ptable_ConvDesign, [](QTableWidgetItem* item)
                      {
                          if (item->column() == 1 || item->column() == 2)
                          {
                              auto CleanVol_item  = item->tableWidget()->item(item->row(), (item->column() + 1)%2);
                              auto PropVol_item = item->tableWidget()->item(item->row(), 3);
          
                              double val1 = item->data(Qt::DisplayRole).toDouble();
                              double val2 = CleanVol_item->data(Qt::DisplayRole).toDouble();
          
                              PropVol_item->setData(Qt::DisplayRole, val1 * val2);
                          }
                      });
              }
          }
          

          }

          1 Reply Last reply
          0
          • Chris KawaC Online
            Chris KawaC Online
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #6

            There are many problems in your code. Where to start?...

            I'm not sure you're aware that C++ uses 0-based indexing. Column 3 is thus item->column() == 2. So if you want to multiply first and second column and store in third then you multiply index 0 with index 1 and store in index 2.

            Next, In your first for loop you only put items in column 0, so if you try to access any other column (either read or write) your app will crash. Put empty items in columns 1 and 2 if you don't want to fill them at startup.

            Next, you should only make the connect once, not for every cell in the table! Now you have dozens of identical connections firing when you change a single value.

            Here connect(m_ptable_ConvDesign, &QTableWidget::itemChanged, m_ptable_ConvDesign, [](QTableWidgetItem* item) you're missing ui-> before both m_ptable_ConvDesign. If it compiles you have something wrong in your code because m_ptable_ConvDesign would have to be a local variable.

            As mentioned before if (item->column() == 1 || item->column() == 2) will match second and third column, not first and second.

            This trick (item->column() + 1)%2 only works for 0 and 1: (0+1)%2 = 1, (1+1)%2 = 0. For values 1 and 2 in your code it results in garbage: (1+1)%2 = 0, (2+1)%2 = 1. If you're not comfortable with modulo arithmetic just use a branch expression: (item->column() == 1) ? 2 : 1.

            As mentioned above this item->tableWidget()->item(item->row(), 3); gets an item in fourth column, not third.

            AbderaoufA 3 Replies Last reply
            4
            • Chris KawaC Chris Kawa

              There are many problems in your code. Where to start?...

              I'm not sure you're aware that C++ uses 0-based indexing. Column 3 is thus item->column() == 2. So if you want to multiply first and second column and store in third then you multiply index 0 with index 1 and store in index 2.

              Next, In your first for loop you only put items in column 0, so if you try to access any other column (either read or write) your app will crash. Put empty items in columns 1 and 2 if you don't want to fill them at startup.

              Next, you should only make the connect once, not for every cell in the table! Now you have dozens of identical connections firing when you change a single value.

              Here connect(m_ptable_ConvDesign, &QTableWidget::itemChanged, m_ptable_ConvDesign, [](QTableWidgetItem* item) you're missing ui-> before both m_ptable_ConvDesign. If it compiles you have something wrong in your code because m_ptable_ConvDesign would have to be a local variable.

              As mentioned before if (item->column() == 1 || item->column() == 2) will match second and third column, not first and second.

              This trick (item->column() + 1)%2 only works for 0 and 1: (0+1)%2 = 1, (1+1)%2 = 0. For values 1 and 2 in your code it results in garbage: (1+1)%2 = 0, (2+1)%2 = 1. If you're not comfortable with modulo arithmetic just use a branch expression: (item->column() == 1) ? 2 : 1.

              As mentioned above this item->tableWidget()->item(item->row(), 3); gets an item in fourth column, not third.

              AbderaoufA Offline
              AbderaoufA Offline
              Abderaouf
              wrote on last edited by
              #7

              @Chris-Kawa
              For now; I would like to confirm the columns assignments:

              I am using the first column as an indicator of the stage type; the second and the third are input data and the fourth in the result.

              Thanks for your comments. Let me make the changes and I will let you know.

              Cheers;

              Raouf

              1 Reply Last reply
              0
              • Chris KawaC Chris Kawa

                There are many problems in your code. Where to start?...

                I'm not sure you're aware that C++ uses 0-based indexing. Column 3 is thus item->column() == 2. So if you want to multiply first and second column and store in third then you multiply index 0 with index 1 and store in index 2.

                Next, In your first for loop you only put items in column 0, so if you try to access any other column (either read or write) your app will crash. Put empty items in columns 1 and 2 if you don't want to fill them at startup.

                Next, you should only make the connect once, not for every cell in the table! Now you have dozens of identical connections firing when you change a single value.

                Here connect(m_ptable_ConvDesign, &QTableWidget::itemChanged, m_ptable_ConvDesign, [](QTableWidgetItem* item) you're missing ui-> before both m_ptable_ConvDesign. If it compiles you have something wrong in your code because m_ptable_ConvDesign would have to be a local variable.

                As mentioned before if (item->column() == 1 || item->column() == 2) will match second and third column, not first and second.

                This trick (item->column() + 1)%2 only works for 0 and 1: (0+1)%2 = 1, (1+1)%2 = 0. For values 1 and 2 in your code it results in garbage: (1+1)%2 = 0, (2+1)%2 = 1. If you're not comfortable with modulo arithmetic just use a branch expression: (item->column() == 1) ? 2 : 1.

                As mentioned above this item->tableWidget()->item(item->row(), 3); gets an item in fourth column, not third.

                AbderaoufA Offline
                AbderaoufA Offline
                Abderaouf
                wrote on last edited by
                #8

                @Chris-Kawa
                Thank you man for your support. The code is working and is described below for those who wand to do the same:

                ui(new Ui::CFAdvisor)
                {
                ui->setupUi(this);

                ui->m_ptable_Conv->setItem(0, 0, new QTableWidgetItem("Type1"));
                ui->m_ptable_Conv->setItem(1, 0, new QTableWidgetItem ("Type2"));
                
                    for (int row = 2; row < ui->m_ptable_Conv->rowCount()-9; ++row)
                    {
                        for (int column = 0; column < ui->m_ptable_Conv->columnCount(); ++column)
                        {
                         ui->m_ptable_Conv->setItem(row, 0, new QTableWidgetItem ("Type3"));
                        }
                    }
                ui->m_ptable_Conv->setItem(10, 0, new QTableWidgetItem ("Type4"));
                
                for (int row = 0; row < ui->m_ptable_Conv->rowCount(); ++row)
                {
                    for (int column = 1; column < ui->m_ptable_Conv->columnCount(); ++column)
                    {
                        QTableWidgetItem *newItem = new QTableWidgetItem();
                        ui->m_ptable_Conv->setItem(row, column, newItem);
                    }
                }
                    connect(ui->m_ptable_Conv, &QTableWidget::itemChanged, ui->m_ptable_Conv, [](QTableWidgetItem* item)
                            {
                                if (item->column() == 1 || item->column() == 2)
                                {
                                    auto Input1_item  = item->tableWidget()->item(item->row(), 1);
                                    auto Input2_item  = item->tableWidget()->item(item->row(), 2);
                                    auto Result_item = item->tableWidget()->item(item->row(), 3);
                
                                    double val1 = Input1_item->data(Qt::DisplayRole).toDouble();
                                    double val2 = Input2_item->data(Qt::DisplayRole).toDouble();
                
                                    Result_item->setData(Qt::DisplayRole, val1 * val2);
                                }
                            });
                
                1 Reply Last reply
                0
                • Chris KawaC Chris Kawa

                  There are many problems in your code. Where to start?...

                  I'm not sure you're aware that C++ uses 0-based indexing. Column 3 is thus item->column() == 2. So if you want to multiply first and second column and store in third then you multiply index 0 with index 1 and store in index 2.

                  Next, In your first for loop you only put items in column 0, so if you try to access any other column (either read or write) your app will crash. Put empty items in columns 1 and 2 if you don't want to fill them at startup.

                  Next, you should only make the connect once, not for every cell in the table! Now you have dozens of identical connections firing when you change a single value.

                  Here connect(m_ptable_ConvDesign, &QTableWidget::itemChanged, m_ptable_ConvDesign, [](QTableWidgetItem* item) you're missing ui-> before both m_ptable_ConvDesign. If it compiles you have something wrong in your code because m_ptable_ConvDesign would have to be a local variable.

                  As mentioned before if (item->column() == 1 || item->column() == 2) will match second and third column, not first and second.

                  This trick (item->column() + 1)%2 only works for 0 and 1: (0+1)%2 = 1, (1+1)%2 = 0. For values 1 and 2 in your code it results in garbage: (1+1)%2 = 0, (2+1)%2 = 1. If you're not comfortable with modulo arithmetic just use a branch expression: (item->column() == 1) ? 2 : 1.

                  As mentioned above this item->tableWidget()->item(item->row(), 3); gets an item in fourth column, not third.

                  AbderaoufA Offline
                  AbderaoufA Offline
                  Abderaouf
                  wrote on last edited by
                  #9

                  @Chris-Kawa
                  I have a new challenge and I am wondering if you have time to help out. I want to caluculate column 5 which is the result of Column 3 + (factor * Column 4).
                  The factor is a static input outside the table. The error I had were: the factor is not captured and is a static.

                  Your support is welcome.

                  Cheers;

                  Raouf

                  jsulmJ 1 Reply Last reply
                  0
                  • AbderaoufA Abderaouf

                    @Chris-Kawa
                    I have a new challenge and I am wondering if you have time to help out. I want to caluculate column 5 which is the result of Column 3 + (factor * Column 4).
                    The factor is a static input outside the table. The error I had were: the factor is not captured and is a static.

                    Your support is welcome.

                    Cheers;

                    Raouf

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Abderaouf Why don't you show the code?
                    How exactly is this static factor declared and where?

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

                    1 Reply Last reply
                    0
                    • Chris KawaC Online
                      Chris KawaC Online
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      The error says it all: you need to capture the value before you can use it inside a lambda. For example if the input is a global static like this static int foo = 42; you would capture a reference to it like this:[&foo](QTableWidgetItem* item)

                      AbderaoufA 1 Reply Last reply
                      2
                      • Chris KawaC Chris Kawa

                        The error says it all: you need to capture the value before you can use it inside a lambda. For example if the input is a global static like this static int foo = 42; you would capture a reference to it like this:[&foo](QTableWidgetItem* item)

                        AbderaoufA Offline
                        AbderaoufA Offline
                        Abderaouf
                        wrote on last edited by
                        #12

                        @Chris-Kawa

                        below is the code I came up with. @jsulm the static factor is declared in a groupe box in the first tab and is copied in another groupe box in the second tab where the table is so the user can know what factor he s using without going back and forth, the factor is not a global static one. The calculation is done but with a wrong result: colulmn 5 = colulmn 3 without the additional factor * column 4. I am pretty sure there is a mistake in the declaration.

                        Cheers;

                        Raouf

                        static double AVF = ui->Input_PropAVF->text().toDouble();
                        ui->label_PropAVF1->setText(QString::number(AVF));

                            connect(ui->m_ptable_ConvDesign, &QTableWidget::itemChanged, ui->m_ptable_ConvDesign, [&AVF](QTableWidgetItem* item)
                                       {
                                       if (item->column() == 2 || item->column() == 3)
                                        {
                                            auto CleanVol_item  = item->tableWidget()->item(item->row(), 2);
                                            auto PropVol_item = item->tableWidget()->item(item->row(), 3);
                                            auto SlurryVol_item  = item->tableWidget()->item(item->row(), 4);
                        
                                            double val1 = CleanVol_item->data(Qt::DisplayRole).toDouble();
                                            double val2 = PropVol_item->data(Qt::DisplayRole).toDouble();
                        
                                            SlurryVol_item->setData(Qt::DisplayRole, (AVF * val2) + val1);
                                        }
                                    });
                        
                        1 Reply Last reply
                        0
                        • Chris KawaC Online
                          Chris KawaC Online
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          Aww, that doesn't look right.
                          Why do you use a text input widget when you want a number? Using text to store a double is just weird. Better use something like QDoubleSpinBox and then you get the double value directly.
                          You don't need a static variable to pass it to that lambda. I only gave that example because you said you have a static input, which you don't really seem to.
                          Just capture this by reference and use the value directly:

                          [&](QTableWidgetItem* item) {
                              ...
                              SlurryVol_item->setData(Qt::DisplayRole, (ui->Input_PropAVF->text().toDouble() * val2) + val1);
                          }
                          

                          If you used a proper QDoubleSpinBox it would be like this:

                          [&](QTableWidgetItem* item) {
                              ...
                              SlurryVol_item->setData(Qt::DisplayRole, (ui->Input_PropAVF->value() * val2) + val1);
                          }
                          
                          AbderaoufA 2 Replies Last reply
                          1
                          • Chris KawaC Chris Kawa

                            Aww, that doesn't look right.
                            Why do you use a text input widget when you want a number? Using text to store a double is just weird. Better use something like QDoubleSpinBox and then you get the double value directly.
                            You don't need a static variable to pass it to that lambda. I only gave that example because you said you have a static input, which you don't really seem to.
                            Just capture this by reference and use the value directly:

                            [&](QTableWidgetItem* item) {
                                ...
                                SlurryVol_item->setData(Qt::DisplayRole, (ui->Input_PropAVF->text().toDouble() * val2) + val1);
                            }
                            

                            If you used a proper QDoubleSpinBox it would be like this:

                            [&](QTableWidgetItem* item) {
                                ...
                                SlurryVol_item->setData(Qt::DisplayRole, (ui->Input_PropAVF->value() * val2) + val1);
                            }
                            
                            AbderaoufA Offline
                            AbderaoufA Offline
                            Abderaouf
                            wrote on last edited by
                            #14

                            @Chris-Kawa Wow, this is a kids game for you isn't it. I regret I didn t study this when I had the chance.

                            Thanks man

                            1 Reply Last reply
                            0
                            • Chris KawaC Chris Kawa

                              Aww, that doesn't look right.
                              Why do you use a text input widget when you want a number? Using text to store a double is just weird. Better use something like QDoubleSpinBox and then you get the double value directly.
                              You don't need a static variable to pass it to that lambda. I only gave that example because you said you have a static input, which you don't really seem to.
                              Just capture this by reference and use the value directly:

                              [&](QTableWidgetItem* item) {
                                  ...
                                  SlurryVol_item->setData(Qt::DisplayRole, (ui->Input_PropAVF->text().toDouble() * val2) + val1);
                              }
                              

                              If you used a proper QDoubleSpinBox it would be like this:

                              [&](QTableWidgetItem* item) {
                                  ...
                                  SlurryVol_item->setData(Qt::DisplayRole, (ui->Input_PropAVF->value() * val2) + val1);
                              }
                              
                              AbderaoufA Offline
                              AbderaoufA Offline
                              Abderaouf
                              wrote on last edited by VRonin
                              #15

                              @Chris-Kawa , hello man;

                              I have a new challenge, hope this is the last.

                              The next operation I need to do is calculating the items of a given column, column 4, of a given table, m_ptable_Conductor, from a column 4 of another table, m_ptable_ConvDesign, using a value storedd in QLineEdit; as follows:
                              SlurryVolCond_item->setData(Qt::DisplayRole, qRound(val1 * (ui->Input_DesSLF-> text().toDouble())));

                              The results will populate the column of table 2 upon click on a push button.

                              I have prepared the below code, there's no error but nothing is changing in table 2.

                              void CFAdvisor::on_Button4_clicked()
                              {
                                  connect(ui->m_ptable_Conductor, &QTableWidget::itemChanged, ui->m_ptable_ConvDesign, [&](QTableWidgetItem* item)
                                             {
                                             if (item->column() == 4)
                                              {
                                                  auto SlurryVolConv_item = ui->m_ptable_ConvDesign->item(item->row(), 4);
                                                  auto SlurryVolCond_item  = item->tableWidget()->item(item->row(), 4);
                              
                                                  double val1 = SlurryVolConv_item->data(Qt::DisplayRole).toDouble();
                                                  
                                                  SlurryVolCond_item->setData(Qt::DisplayRole, qRound(val1 * (ui->Input_DesSLF-> text().toDouble())));
                              
                                                 
                                                  }
                              
                                          });
                              }
                              

                              Thanks

                              1 Reply Last reply
                              0
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                Hi
                                Put a breakpoint at
                                if (item->column() == 4)
                                and single step from there. You can then see what values u take etc.

                                AbderaoufA 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  Hi
                                  Put a breakpoint at
                                  if (item->column() == 4)
                                  and single step from there. You can then see what values u take etc.

                                  AbderaoufA Offline
                                  AbderaoufA Offline
                                  Abderaouf
                                  wrote on last edited by VRonin
                                  #17

                                  @mrjj
                                  Thanks mrjj. I think I fixed that based on Chris-kawa previous comments. I have another issue. I want to creat a Qpushbutton that fill the items of the second table based on the data of the first table using an if condition that check the QString of the 2nd column. If the value is "Y", the calculation should be on one way and if the value is "N" the calculation are done in another way. The code is not showing any error but .exe is crashing when I push the button. below is my code, thanks for reviewing it and advising:

                                  void CFAdvisor::on_Button4_clicked()
                                      {
                                      QString str1;
                                      QString str2 = "Y";
                                      QString str3 = "N";
                                  
                                        for (int row = 0; row < ui->m_ptable_ConvDesign->rowCount(); ++row)
                                        {
                                            QTableWidgetItem *stagepulse_item = ui->m_ptable_ConvDesign->item(row, 1);
                                            str1 = stagepulse_item->data(Qt::DisplayRole).toString();
                                        }
                                  
                                      for (int column = 0; column < ui->m_ptable_Conductor->columnCount(); ++column)
                                      {
                                        for (int row = 0; row < ui->m_ptable_Conductor->rowCount(); ++row)
                                        {
                                            if (str1 == str2)
                                             {
                                  
                                          QTableWidgetItem *PropConCond_item = ui->m_ptable_Conductor->item(row, 1);
                                          QTableWidgetItem *PropConConv_item = ui->m_ptable_ConvDesign->item(row,2);
                                          PropConCond_item->setData(Qt::DisplayRole,PropConConv_item->text().toDouble());
                                  
                                          QTableWidgetItem *SlurryVolCond_item = ui->m_ptable_Conductor->item(row, 4);
                                          QTableWidgetItem *SlurryVolConv_item = ui->m_ptable_ConvDesign->item(row,5);
                                          SlurryVolCond_item->setData(Qt::DisplayRole,qRound(((ui->Input_DesSLF-> text().toDouble())) * (SlurryVolConv_item->text().toDouble())));
                                  
                                          QTableWidgetItem *CleanVolCond_item = ui->m_ptable_Conductor->item(row, 2);
                                          CleanVolCond_item->setData(Qt::DisplayRole,qRound((SlurryVolCond_item->text().toDouble()) / ( 1 + ((ui->label_PropAVF1->text().toDouble()) * (PropConCond_item->text().toDouble())))));
                                  
                                             }
                                  
                                             if (str1 == str3)
                                             {
                                  
                                          QTableWidgetItem *PropConCond_item = ui->m_ptable_Conductor->item(row, 1);
                                          QTableWidgetItem *PropConConv_item = ui->m_ptable_ConvDesign->item(row,2);
                                          PropConCond_item->setData(Qt::DisplayRole,PropConConv_item->text().toDouble());
                                  
                                          QTableWidgetItem *SlurryVolCond_item = ui->m_ptable_Conductor->item(row, 4);
                                          QTableWidgetItem *SlurryVolConv_item = ui->m_ptable_ConvDesign->item(row,5);
                                          SlurryVolCond_item->setData(Qt::DisplayRole,SlurryVolConv_item->text().toDouble());
                                  
                                          QTableWidgetItem *CleanVolCond_item = ui->m_ptable_Conductor->item(row, 2);
                                          CleanVolCond_item->setData(Qt::DisplayRole,qRound((SlurryVolCond_item->text().toDouble()) / ( 1 + ((ui->label_PropAVF1->text().toDouble()) * (PropConCond_item->text().toDouble())))));
                                  
                                             }
                                          }
                                      }
                                  }
                                  

                                  Regards;

                                  Raouf

                                  1 Reply Last reply
                                  0
                                  • mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    Hi
                                    You should check all pointer to QTableWidgetItem * before using them.
                                    It might return NULL and u crash.

                                    Still if you place a break point and single step you should find the line that makes you crash.

                                    AbderaoufA 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      Hi
                                      You should check all pointer to QTableWidgetItem * before using them.
                                      It might return NULL and u crash.

                                      Still if you place a break point and single step you should find the line that makes you crash.

                                      AbderaoufA Offline
                                      AbderaoufA Offline
                                      Abderaouf
                                      wrote on last edited by
                                      #19

                                      @mrjj I think it is that line, where I convert a QtableWidgetItem to QString:

                                      str1 = stagepulse_item->data(Qt::DisplayRole).toString();

                                      The syntax is right, I dont know what is the real reason though.

                                      mrjjM VRoninV 2 Replies Last reply
                                      0
                                      • AbderaoufA Abderaouf

                                        @mrjj I think it is that line, where I convert a QtableWidgetItem to QString:

                                        str1 = stagepulse_item->data(Qt::DisplayRole).toString();

                                        The syntax is right, I dont know what is the real reason though.

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #20

                                        @Abderaouf
                                        It seems correct. You are getting a QVariant from data and call toString.
                                        So when debugging it crash on this line?

                                        AbderaoufA 1 Reply Last reply
                                        0
                                        • AbderaoufA Abderaouf

                                          @mrjj I think it is that line, where I convert a QtableWidgetItem to QString:

                                          str1 = stagepulse_item->data(Qt::DisplayRole).toString();

                                          The syntax is right, I dont know what is the real reason though.

                                          VRoninV Offline
                                          VRoninV Offline
                                          VRonin
                                          wrote on last edited by VRonin
                                          #21

                                          @Abderaouf said in QTableWidget Operations over columns:

                                          I dont know what is the real reason though

                                          probably stagepulse_item is a null pointer

                                          also your logic does not work, at the moment the calculation is based on whether the last line, second column in m_ptable_ConvDesign is Y or N

                                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                          ~Napoleon Bonaparte

                                          On a crusade to banish setIndexWidget() from the holy land of Qt

                                          AbderaoufA 1 Reply Last reply
                                          1

                                          • Login

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