In my code I am creating new objects of same type inside loop and connecting a signal to object slot. Here is my trial.

Qt Code:
  1. A * a;
  2. QList<A *> aList;
  3. int aCounter = 0;
  4. while(aCounter < 2)
  5. {
  6. a = new A;
  7. aList.push_back(a);
  8. connect(this,SIGNAL(somethingHappened()),aList[aCounter],SLOT(doSometing()));
  9. aCounter++;
  10.  
  11. }
To copy to clipboard, switch view to plain text mode 

When somethingHappened signal is emitted. Both objects slot is called. But I need to handle them seperately. Is it wrong to connect signal to a slot inside loop? If not how can I achieve my desire?