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. Edit vector elements when QListWidget Item is edited
Qt 6.11 is out! See what's new in the release blog

Edit vector elements when QListWidget Item is edited

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,

    I have a vector of QString and i added all elements of this vector to the QListWidget. I want to edit elements of vectors by editing elements of QListWidget. I tried to handle this by using pointers but it doesnt help. I can only edit QlistWidget items, changes does not effect vector elements. I can achieve this by writing code that finds the which row of QlistWidged correspond to the which element of vector but i want to find out that is it possible to do it with direct access.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      You need to dive into the Model-View-Controller pattern for that and use the QListView and QAbstractListModel.
      Be easy on yourself if you work with those classes for the first time, it usually takes a bit until it really sinks in.
      The point of this approach is to not duplicate the data in the displaying component (the view), but keeping it all in the back (the model – e.g. owning your vector) in one spot. So by editing something in the view, this editing transaction is directly passed to the model.

      Unfortunately Qt doesn't provide a compromise between full-fledged MVC, which creates quite an amount of overhead, and the ease-of-use of the QList/Table/TreeWidget classes.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I am not familiar with MVC, it seems comprehensive study necessary for learn it. So i found temporary solution for this project. Thanks for your answer.

        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