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. The return value of QAbstractItemModel::setData()
QtWS25 Last Chance

The return value of QAbstractItemModel::setData()

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.4k 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.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by
    #1

    when reimplement QAbstractItemModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )
    as for the roles that we want to ignore ,what should we do ?
    return false or return true ?or anything else ?

    examples in the Qt documentation are even self-contradictory
    here the return value is false
    http://qt-project.org/doc/qt-4.8/model-view-programming.html#making-the-model-editable
    but here the return value is true
    http://qt-project.org/doc/qt-4.8/modelview.html#2-5-the-minimal-editing-example

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

      Hi,

      The simple way is to return the result of default implementation (IIRC it's false), so you should be safe.

      @return QAbstractItemModel::setData(index, value, role)@

      As for the why they return true in the example, it's explain under setData code.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redstoneleo
        wrote on last edited by
        #3

        but I think the default implementation is the same as return false
        [quote author="SGaist" date="1365509933"]Hi, The simple way is to return the result of default implementation (IIRC it's false), so you should be safe. @return QAbstractItemModel::setData(index, value, role)@ As for the why they return true in the example, it's explain under setData code. Hope it helps[/quote]

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's exactly what I said

          The plus side of using the default implementation return value is that if this value should change (I highly doubt that in this case) you have the change for free.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            redstoneleo
            wrote on last edited by
            #5

            so in this case both return QAbstractItemModel::setData(index, value, role) or false will be ok ,right ?

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

              I do not think so. Look at doc:
              Sets the role data for the item at index to value.

              Returns true if successful; otherwise returns false.

              The dataChanged() signal should be emitted if the data was successfully set.

              The base class implementation returns false. This function and data() must be reimplemented for editable models.

              The base class returns false as it do not set any data (setting data is not successful).
              Your implementation should return true in case setting data is successful and false otherwise.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                redstoneleo
                wrote on last edited by
                #7

                [quote author="Achab" date="1366534451"] Your implementation should return true in case setting data is successful and false otherwise.[/quote]
                sorry for my poor english ,what I actually want to express is that "return true in case setting data is successful ,otherwise return QAbstractItemModel::setData(index, value, role) or false has the same effect ",what about your opinion ?

                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