[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..

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

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

    the error will appear if you leave the cell empty.



  • [quote author="xeroblast" date="1293521365"]i have this little problem that uses a lot of my time. this is about the qtablewidgetitem identifying if it is empty or not..

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

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

    the error will appear if you leave the cell empty.[/quote]

    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:

    bq. 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.



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



  • [quote author="xeroblast" date="1293527835"]i cant use qtableview because the table is editable by double clicking..[/quote]

    You can do that as well. But read more about "Model/View Programming":http://doc.qt.nokia.com/latest/model-view-programming.html and see that you can do more cool things besides basic editing.



  • 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:

    @
    for (int row=0; row < rows; ++row) {
    if(QTableWidgetItem *item = qtablewidget->item(row, col)) {
    if(item->text().isEmpty()) {
    }
      }
    }
    @



  • Â 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.



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

    @
    for (int row=0; row < rows; row++) {
    if (!qtablewidget->item(row, col)) {
    }
    }
    @



  • 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]

    [quote author="xeroblast" date="1293587463"]thank you..
    i also solve it using it like this :
    @
    for (int row=0; row < rows; row++) {
    if (!qtablewidget->item(row, col)) {
    }
    }
    @[/quote]

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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.