Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading Value from a QTablewidget
Qt 6.11 is out! See what's new in the release blog

Reading Value from a QTablewidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deleted543
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

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

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved