c++ - Dynamically create new instances of a custom widget & connect signals & slots (Qt) -


part a:

i have created widget called panel i'd iteratively make new instances of.

so, example, like:

 panel *panelarray[10];  for(int i=0;i<10;i++) panelarray[i] = new panel(this); 

would appropriate syntax?

part b:

if so, how manually hook signals emitted each of panels?

example:

 for(int i=0;i<10,i++) connect(panelarray[i], signal(raisetoggleguicmd(qbytearray)), this, slot(writedata(qbytearray))); 

thanks in advance!

part looks normal.

part b looks normal too, if want know widget emit signal, should use this( in case, slot same thing every widget)

usage of qsignalmapper

signalmapper = new qsignalmapper(this); (int = 0; < 3; ++i)    {        qpushbutton *button = new qpushbutton(qstring::number(i),this);        connect(button, signal(clicked()), signalmapper, slot(map()));        button->move(i*10,i*10);//doesn't matter         signalmapper->setmapping(button, qstring::number(i));    } connect(signalmapper, signal(mapped(const qstring &)),             this, slot(clicked(const qstring &)));  //... void mainwindow::clicked(const qstring & text) {     qmessagebox::information(this, "test", text, qmessagebox::ok); } 

or using sender()

for (int = 0; < 3; ++i)    {        qpushbutton *button = new qpushbutton(qstring::number(i),this);        button->setobjectname(qstring::number(i));//important        connect(button, signal(clicked()), this, slot(clicked()));        button->move(i*10,i*10);    }  void mainwindow::clicked() {     switch( sender()->objectname().toint())     {         case 0:         qmessagebox::information(this, "test", "0", qmessagebox::ok);//do specific 0 widget         break;     case 1:     qmessagebox::information(this, "test", "1", qmessagebox::ok);//do specific 1 widget     break;     case 2:     qmessagebox::information(this, "test", "2", qmessagebox::ok);//and on     break;     } } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -