Results 1 to 2 of 2

Thread: Create sharable container of multiple QWidgets

  1. #1
    Join Date
    Jun 2015
    Posts
    109
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Create sharable container of multiple QWidgets

    Hello,

    I have multiple QWidgets and want to share each widget with each other for sharing each other data.

    I have created multiple widgets and there are other ways to share widget data by sharing pointer with each other, but is there an elegant solution where I can create a simple container to add all the widgets in it and make this container shareable to each other without passing to each other.

    Please share your suggestions.

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create sharable container of multiple QWidgets

    What do you mean "share each other's data"? Do you want every widget to know about child widgets or other member variable values inside the other widgets? That is a bad idea.

    If you want to be able to notify other widgets when one widget's state changes, then a better way is to use signals and slots.

    It sounds like you might need some kind of "broadcast" system - when one widget changes, then all other widgets need to know about the change. This requires a "middle man" class that receives signals from each widget and then emits is own signal to the others. In this way you don't have to connect all of the widget signals and slots together - the middle man takes care of it.

    You might be able to use QSignalMapper for this. With this class, every widget's signal is connected to the QSignalMapper::map() slot. In addition, you connect the signal mapper's mapped() signal to the slot each widget uses to listen for changes. There is a version of the QSignalMapper::map() and QSignalMapper::mapped() combo that allows the widget pointers to be passed.

    If QSignalMapper itsef is not suitable (for example, you need to pass parameters - QSignalMapper works only for signals with no parameters), then you can implement your own QObject-based class that does the same idea - every widget's signal is connected to a slot in the middleman class, and every widget has a slot that is connected to a middleman signal. This could be very flexible - your middleman could have many signal / slot pairs, each one handling a different connection between the widgets.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 5
    Last Post: 22nd March 2017, 09:50
  2. Painting in multiple QWidgets simultaneously
    By edepetete in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2011, 18:21
  3. Replies: 0
    Last Post: 16th January 2011, 03:35
  4. Why do some QWidgets create own threads?
    By donglebob in forum Qt Programming
    Replies: 5
    Last Post: 6th July 2010, 18:01
  5. Multiple QWidgets
    By codeman in forum Qt Programming
    Replies: 7
    Last Post: 23rd March 2010, 12:21

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.