January 18, 2012

kumpane kumpane
Lab Rat
3 posts

SIGSEGV tableitem->text()

 

I have to write a funktion which is matching the content between a QTreeWidget and the QTableWidget.
I’m pretty sure i got the same problem like here http://lists.trolltech.com/qt-interest/2006-02/thread01488-0.html
I try it with that if clause if(!tableitem) but the error appears anyway. The findItems functions works great and the text() function in the top works great too. I follow the behavior in the debugger a couple of times and all the time it is the tableitem which i used in the top too. The treeitem is not the problem. After the erros appears the debugger jump into qtablewidget.h.

Here is a picture of the data with the debugger
http://imageshack.us/photo/my-images/835/bildschirmfotoam2012011.png

  1.  //qtablewidget.h line 107
  2.     inline QString text() const
  3.         { return data(Qt::DisplayRole).toString(); }
  4.     inline void setText(const QString &text);

  1. QList<QTreeWidgetItem*> treelist=ui->treeMux->findItems("PORT ",Qt::MatchContains| Qt::MatchRecursive,0);
  2. QList<QTableWidgetItem*> tablelist=ui->tableTS->findItems("^[0-9]{1,2}$",Qt::MatchRegExp);
  3.  
  4. foreach(QTableWidgetItem* tableitem,tablelist)
  5. {
  6.   if(!tableitem)
  7.   {continue;}
  8.   else
  9.   {
  10.       if(tableitem->row()==0)
  11.       {
  12.           muxmaker->set_vects1(tableitem->column(),tableitem->text()); // HERE IT WORKS!
  13.           ts1--;
  14.        }
  15.        if(tableitem->row()==1)
  16.       {
  17.           muxmaker->set_vects2(tableitem->column(),tableitem->text()); // HERE IT WORKS TOO!
  18.            ts2--;
  19.        }
  20.        foreach(QTreeWidgetItem* treeitem,treelist)
  21.       {
  22.        treeitem->setCheckState(2,Qt::Unchecked);
  23.             if(treeitem->text(0).contains(tableitem->text())) // HERE IS THE ERROR WITH  tableitem->text()
  24.             treeitem->setCheckState(2,Qt::Checked);
  25.        }
  26.    }
  27. }

The problem have to be so simple that i couldnt see it …. please excuse me fo my foolery

1 reply

January 18, 2012

kumpane kumpane
Lab Rat
3 posts

ops…..in the debugger picture you wil see a variable called strr , i add the variable to see if it is the treeitem or the tableitem…here is the code it will explain “everyting”

  1. treeitem->setCheckState(2,Qt::Unchecked);
  2. QString strr = treeitem->text(0);
  3. if(strr.contains(tableitem->text()))
  4. treeitem->setCheckState(2,Qt::Checked);

if i try this it crashs

  1.                 QString str=tableitem->text();

if i try this it works

  1.               cout<<tableitem->text().toStdString()<<endl;

What is the problem?? Maybe it is the Display Role?? or something like else?

 
  ‹‹ [Solved]QThread Output in QTextEdit without emitors.      [Solved]Repaint widget after qss ››

You must log in to post a reply. Not a member yet? Register here!