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. How can i associate a GUId for each row i create in QTableView
Forum Update on Monday, May 27th 2025

How can i associate a GUId for each row i create in QTableView

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.2k Views
  • 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi

    I want to associate a GUID for each row i create in QTableView.
    So that i can retrieve it back when user clicks on particular row.

    How to do this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Have the underlying model create one.

      It seems overkill for me to use a GUID for a row in a table though.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Indrajeet
        wrote on last edited by
        #3

        Hi Andre

        I want to associate some string data to each row so that i can fetch it back when user clicks the row and use that string for further processing.

        How to do this?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          What model do you use? The basic way to do it is to just use a custom role (Qt::UserRole+n), and make your model return the needed data when asked for it for the current index. How you do that exactly, depends on the model you use.

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Indrajeet
            wrote on last edited by
            #5

            HI Andre

            I use QStandardItemModel.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              In that case, use QStandardItem::setData().
              Note that you'll have to do that for every item on the row, you will have to subclass QStandardItemModel to return the value from the first column for this role for every column, or something like that. You'd have to reimplement the data() method for that.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Indrajeet
                wrote on last edited by
                #7

                Hi Andre

                Can you please help me to show how to do it.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  No, now it is your turn to show what you have tried. I have no interest in doing your work or school assignment for you.

                  1 Reply Last reply
                  0

                  • Login

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