How to read null value from QTableWidget?



  • In my QTableWidget, there exist some cells whose values are Null(it contains nothing)
    But when i'm trying to read table widget, if it encounters null cell, program crashes...
    How can i get rid of this problem?



  • if item at cell is null - then at cell - is nothing ;)



  • Such cells present in between, because of such null cells i'm unable to do any operation on that table....



  • @
    QTableWidgetItem *item = tableWidget->item(5, 7);
    if(item) {
    // the item exists
    // do something with it
    // it is safe to call
    QString t = item->text();
    } else {
    // the item does NOT exist
    // you have a NULL pointer here
    // NEVER call item->xxx here, the program will crash
    // you may call this a NULL item
    // if you want to do something here, create an item
    // and put it into the table widget
    }
    @


Log in to reply
 

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