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. problem with QTableWidget and comboBox
Forum Updated to NodeBB v4.3 + New Features

problem with QTableWidget and comboBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 326 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.
  • F Offline
    F Offline
    frnklu20
    wrote on last edited by frnklu20
    #1

    Hi,

    Let me explain the situation. My program is based in a QDialog that contains a ComboBox and a QTableWidget, and the item selected in the combobox change some non-editable items in the QTableWidget.

    Here is the code

    void GeradorDialog::on_type_box_currentTextChanged(const QString &arg1)
    {
        if(ui->type_box->currentText()=="(V0) Contr. Tensão/Âng."){
            //type_box is the combobox
            item1->setText("Vref");
            unid_item1->setText("pu");
            item2->setText("Aref");
            unid_item2->setText("rad");
            //tabela_fluxo is the QTableWidget
            ui->tabela_fluxo->setItem(0,2,new QTableWidgetItem("1"));
            ui->tabela_fluxo->setItem(1,2,new QTableWidgetItem("0"));
    
    
    
        }
        if(ui->type_box->currentText()=="(PV) Contr. Tensão"){
            item1->setText("P");
            unid_item1->setText("MW");
            item2->setText("Vref");
            unid_item2->setText("pu");
            ui->tabela_fluxo->setItem(0,2,new QTableWidgetItem("0"));
            ui->tabela_fluxo->setItem(1,2,new QTableWidgetItem("1"));
    
    
        }
        if(ui->type_box->currentText()=="(PQ)Sem Controle"){
            item1->setText("P");
            unid_item1->setText("MW");
            item2->setText("Q");
            unid_item2->setText("Mvar");
            ui->tabela_fluxo->setItem(0,2,new QTableWidgetItem("0"));
            ui->tabela_fluxo->setItem(1,2,new QTableWidgetItem("0"));
    
        }
    }
    

    So far so good, in the dialog i have a ok button and after it is triggered it emits a signal that saves al the items texts of the QTableItem in a list

    void GeradorDialog::changevalues(int i, QString value)
    {
        data[i]=value;//data is a QStringList
    }
    
    void GeradorDialog::on_buttonBox_clicked()
    {
    
        QMessageBox::StandardButton resposta=QMessageBox::question(this,"","Deseja salvar esses parametros?",QMessageBox::Yes|QMessageBox::No);
        if(resposta==QMessageBox::Yes)
        {
            changevalues(0,ui->name_line->text());
            changevalues(1,ui->area_line->text());
            changevalues(2,ui->sub_line->text());
            changevalues(3,ui->circuito_line->text());
            changevalues(4,Vnom->text());
            changevalues(5,Snom->text());
            changevalues(6,Item1->text());
            changevalues(7,Item2->text());
            changevalues(8,Pmin->text());
            changevalues(9,Pmax->text());
            changevalues(10,Qmin->text());
            changevalues(11,Qmax->text());
    
            this->close();
    
    }
    

    The problem is that when i click the ok button with the default item in the combo box it works just fine, but if i select another item and press the ok button the porgam crashes. I used Qdebug and it gives me an error in theses lines with the function text:

     changevalues(6,Item1->text());
     changevalues(7,Item2->text());
    

    these QTableItems are changed when i select another item in combo box, but i don't know why it's crashing

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

      Hi,

      How are you changing these values ?
      Looks like you could be re-creating these items rather than updating their content and make these pointers invalid.

      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
      0
      • F Offline
        F Offline
        frnklu20
        wrote on last edited by
        #3

        i'm using setText, why it would make it invalid?

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

          If using only setText it should not.

          You should run the debugger and check exactly what happens to your items while changing their value.

          I saw that you are replacing some while you use setText for others. Check that you are not replacing items that you have pointers to.

          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
          1

          • Login

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