Reading Value from a QTablewidget



  • I have a Qtable widget where I want to extract the value in one of the cells, and then make a series of calculations. I will then enter the result of that calculation in another cell.

    I cannot seem to find any way to extract a value from the table.

    I use thefollowing:

    QTableWidgetItem *madeItem = ui->tableWidget->item(0,4);
    

    The program then stops at this point in qtablewidget.h.

    inline QString text() const
        { return data(Qt::DisplayRole).toString(); }
    inline void setText(const QString &text);
    

    What am I missing?


  • Qt Champions 2016

    @bliss said in Reading Value from a QTablewidget:

    Hi and welcome

    madeItem

    and its not NULL ?

    And everything is setup correctly ? with row,col count ?
    https://wiki.qt.io/How_to_Use_QTableWidget

    If you reference invalid cell ( empty as no item assigned) that would result in something like that.



  • ui->tableWidget->model()->index(0,4).data(); this returns a QVariant


Log in to reply
 

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