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. Pass information from tableWidget to another window

Pass information from tableWidget to another window

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

    Hi everyone,

    I use Qt/MySql.
    I created a window "table" where there is a table (TableWidget) that contains some people's information.
    I created a slot so that if we double click on a row, a second window "details" appears.
    My question is how to pass the information of the row that is double clicked to the window "details".

    Thanks.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      The doubleClick() signal passes a QModelIndex, which contains the information needed (amongst others the row and the column).

      How you pass this information to your detail window is a question of taste. You can add an additional QModelIndex index or int row parameter to your constructor or have an explicit setter, which allows you to pass an index or a row.

      Be aware that if you want to store the index for further reference, you will have to use a QPersistentModelIndex, because the ordinary QModelIndex should always be treated as temporary.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        viktor.benei
        wrote on last edited by
        #3

        If you create the 'details' window when the item in the TableWidget selected you can pass the required information to the details window in it's constructor.

        If you need two-way communication (for example if the user can change the data in the 'details' window and it have to pass it back to the TableWidget) the way I usually do this cross-window/object communication is do it with either a simple signal/slot connection or with a delegate object.

        With the signal-slot solution you can create signals in the 'details' window for every action the user can do in the details window (like the user clicked the OK button or the Cancel button) and after you create the details window you simple connect it's signals to slots in your 'parent' window (which contains the TableWidget).

        The delegate based solution is basically the same but instead of creation signals and slots for the communication you pass-in for the 'details' window an additional 'delegate' reference (a reference for the 'parent' window) and the details window will call the delegate's appropriate method(s) when it's needed.

        I would suggest to not to pass the clicked item's index (QModelIndex) but it's actual data to the 'details' window - separation is almost always a good thing (generally it's not good if 2 windows/object can modify each other's internal state/variables directly but rather via a specified interface).

        Both solutions have it's pros and cons like the signal-slot solution is (can be) easily thread-safe without any additional coding to provide thread-safe delegation but if thread safety is not a concern I prefer the delegate based solution because I personally find it as a cleaner solution.

        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