Results 1 to 10 of 10

Thread: dynamically created tablewidget name problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: dynamically created tablewidget name problem

    You always assign to ui.tableWidget, so that holds the reference to the last table widget that got created.

    Cheers,
    _

  2. #2
    Join Date
    Apr 2016
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products

    Default Re: dynamically created tablewidget name problem

    I see. So each tableWidget as it is created is assigned to ui.tablewidget and overwrites the previous one. I need to save each one to a list as it is created, the only problem that I have with that is how do I get them out of the list?

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: dynamically created tablewidget name problem

    A list is usually addressed via index.
    The first item is at index 0, the second at index 1 and so on.

    You can also store the references in an associative container, where the key is not a number but e.g. a string.

    Cheers,
    _

  4. #4
    Join Date
    Apr 2016
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products

    Default Re: dynamically created tablewidget name problem

    I understand that the list is addressed by index, but I don't see how the signal can know what the index is. When the signal is created in the loop and the tableWidget reference is saved to the list, is there some connection that happens so the signal knows what listWidget reference to use?

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: dynamically created tablewidget name problem

    The signal does not know anything about an index, but the slot can get the sender of the signal that caused the slot to be called.

    Alternatively you can create a "signal handler" class, i.e. a class derived from QObject to handle all signals for one single table view, and then create one instance of that class for each table view.

    Cheers,
    _

  6. #6
    Join Date
    Apr 2016
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products

    Default Re: dynamically created tablewidget name problem

    Quote Originally Posted by anda_skoa View Post
    but the slot can get the sender of the signal that caused the slot to be called._
    Could you expand on that a bit? If the slot got the sender of the signal, wouldn't that be the actual reference to the tableWidget so you wouldn't need to save it to a list in the first place?

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: dynamically created tablewidget name problem

    Yes, that would be the actual reference to the tableWidget, whether it is saved somewhere else or not doesn't matter.

    See QObject::sender().

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 18th June 2015, 06:58
  2. use value from dynamically created widget in a slot
    By Cyrebo in forum Qt Programming
    Replies: 55
    Last Post: 23rd April 2013, 14:51
  3. Dynamically created buttons.
    By Tomasz in forum Newbie
    Replies: 26
    Last Post: 2nd December 2010, 09:40
  4. Replies: 7
    Last Post: 2nd August 2010, 12:28
  5. tableWidget created in Qt Creator not updated
    By binaural in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2009, 21:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.