You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, July 4th 2006, 6:31pm

Multiple Widgets of same class - adressing problem

I want to dynamically create 10 (or more) widgets of the same type (name it PlotWidget). These widgets are created within QMainWindow. Each of these widgets will show data of a different data-source.

A Thread is created (inside QMainWindow) for all the computations. Results are stored in this thread for each single data-source.

Now the task is to send the data (maybe via signal/slot) to the mentioned widgets.
My problem is, that when connecting a signal (emitted from the thread) to the slot (inside the widgets), I can't name the target widget. This means, the thread has to iterate over all data-sources and send multiple signals to the widgets. But - how does the widget know, the data is for itself and not for a different widget.

Best way would be to have a mechanismn to register each widget with the thread, so the thread knows it's targets for the different data-sources. But how to accomplish this via signal/slots?
As far as I understand it, there has to be a dedicated signal for each widget to address it directly, but I would like to have it the dynamic way!

Any hints are greatly appreciated.

2

Wednesday, July 5th 2006, 7:21am

I'm guessing that you create the widgets with some kind of loop, and probably another loop for the threads? Try to create the widget and the associated thread at the same time and connect them then, something like the following pssudo-code:

Source code

1
2
3
4
5
6
for (int i = 0; i < 10; ++i)
{
  widget = new Widget(parent);
  thread = new Thread();
  connect(thread, SIGNAL(compDone()), widget, SLOT(update()));
}

3

Wednesday, July 5th 2006, 10:24am

Ok, I have to clarify it:
There's only ONE single thread for all the computations. So this solely thread has to be connected to all the widgets.

But in any case, I have to address each widget individually. The solution of eriwik doesn't allow this. When emitting the signal "compDone" it will be sent to ALL widgets, not only to the widget that seems to be connected. Otherwise you have to use individual signals - but this approach can't be dynamic.

Any other ideas?

4

Saturday, July 8th 2006, 2:56pm

Ok, now I understand. A signal is sent to all objects with a connected slot, as far as I know there's no way to send to just one of them. What you can do it to add a parameter to the signal telling the listening objects what kind of data that has been emited. Then the widgets will have to examine this parameter to decide if they are interested in the content or not.