December 28, 2010

xeroblast xeroblast
Lab Rat
91 posts

[SOLVED] QTableWidgetItem cant read text

 

i have this little problem that uses a lot of my time. this is about the qtablewidgetitem identifying if it is empty or not..

  1. for (int row=0; row < rows; row++) {
  2.   if (qtablewidget->item(row, col)->text().isEmpty()) {
  3.   }
  4. }

the error : Symbol this is a variable with complex or multiple locations (DWARF2)

the error will appear if you leave the cell empty.

8 replies

December 28, 2010

Milot Shala Milot Shala
Lab Rat
393 posts

xeroblast wrote:
i have this little problem that uses a lot of my time. this is about the qtablewidgetitem identifying if it is empty or not..

  1. for (int row=0; row < rows; row++) {
  2.   if (qtablewidget->item(row, col)->text().isEmpty()) {
  3.   }
  4. }

the error : Symbol this is a variable with complex or multiple locations (DWARF2)

the error will appear if you leave the cell empty.

What about using QTableView? You can reach your goal in much nicer way.

On the other hand can you also check if it returns 0, I don’t use QTableWidget myself but according to the documentation, is the statement below:

QTableWidgetItem * QTableWidget::item ( int row, int column ) const
Returns the item for the given row and column if one has been set; otherwise returns 0.

December 28, 2010

xeroblast xeroblast
Lab Rat
91 posts

i cant use qtableview because the table is editable by double clicking..

December 28, 2010

Milot Shala Milot Shala
Lab Rat
393 posts
xeroblast wrote:
i cant use qtableview because the table is editable by double clicking..

You can do that as well. But read more about Model/View Programming [doc.qt.nokia.com] and see that you can do more cool things besides basic editing.

December 28, 2010

Volker Volker
Robot Herder
5428 posts

The error “Symbol this is a variable with complex or multiple locations “ is from the debugger. It’s most likely that you are thrown into the debugger because your application crashes because of a null pointer access. You must check if the item pointer is valid!

Change your method:

  1. for (int row=0; row < rows; ++row) {
  2.   if(QTableWidgetItem *item = qtablewidget->item(row, col)) {
  3.     if(item->text().isEmpty()) {
  4.     }
  5.   }
  6. }

December 28, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

 bit more description to Volkers answer:

In a QTableWidget you can define tghe numbers of rows and columns. By default, no cell has a QTableWidgetItem behind its data, so qtablewidget->item(row, col) will return a null pointer. Only if you fill the table with items, all filled tables will return a valid pointer. So it is a MUST to check the returned pointer.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 29, 2010

xeroblast xeroblast
Lab Rat
91 posts

thank you..
i also solve it using it like this :

  1. for (int row=0; row < rows; row++) {
  2.  if (!qtablewidget->item(row, col)) {
  3.  }
  4. }

December 29, 2010

Volker Volker
Robot Herder
5428 posts

Then you have to call item(row, col) a second time to get to the actual value. This might be quite time consuming if you have a big table. Why not reuse the value that you peeked out just before?

[EDIT: add]

xeroblast wrote:
thank you.. i also solve it using it like this : @ for (int row=0; row < rows; row++) { if (!qtablewidget->item(row, col)) { } } @

The if clause is true, if you have no item at the specified position!

December 30, 2010

xeroblast xeroblast
Lab Rat
91 posts

you are right Volker but i only use it as a checker.. that is why i use the negation..

 
  ‹‹ QString url = prepareFeedURL(itemType, cType); means      How should I use Qt SQL classes to support BLOBs? ››

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