Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, April 2007
Many Slots, QWidgets


Message 1 in thread

Hi All

I have a system where I wish to send a block of data to anywhere up to
91 separate QWidgets  (Called Q1[91] here) which hold information for an
experiment - i.e. voltage, current etc - in principle this number is
probably only about 5.  The data is held in a structure array (Called
Struct[91] here)- i.e. one for each of the 91 elements. 

I currently emit a signal when the base class collates the data:

signal:
    data_out(Structtype *)

to a slot int Q1...

slots:
    data_in(Structtype *)

with

connect (this, SIGNAL(data_out(Structtype *)), &Q1[0],
SLOT(data_in(Structtype *))); for the first set of data.

Is there any way to loop over say 91 elements to set up the connections
so each data_out goes to the correct Q1[i] or do I have to define all
91  data_out() and connection?

Many thanks

Ross

--
 [ signature omitted ] 

Message 2 in thread

Sure, but you should probably store the elements of the array in some  
sort of standard container for convenience, and for possibly future  
expansion. You should also store them by reference. Something like:

std::vector<QWidget*> objects;

objects.push_back( first_object );
objects.push_back( second_object );
// etc...
for ( std::vector<QWidget*>::iterator it = objects.begin();
       it != objects.end();
       ++it )
{
   connect( this, SIGNAL(data_out(Structtype *)),
	*it, SLOT(data_in(Structtype *)) );
}

db

On Apr 24, 2007, at 11:49 AM, Ross Williamson wrote:

> connect (this, SIGNAL(data_out(Structtype *)), &Q1[0],
> SLOT(data_in(Structtype *))); for the first set of data.

--
 [ signature omitted ]