Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QSignalMapper invokes slot multiple times

[ Edited ]

Move the Mapper connection signal outside the loop.

This only needs to be done once for the signalMapper object not for every entry.

 

[Edit] I should have spotted this from the start but my brain went off on a tangent. Smiley Happy

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
New Contributor
Posts: 8
Registered: ‎10-09-2013
My Device: Developer
My Carrier: none

Re: QSignalMapper invokes slot multiple times

The signal mapper is created before the loop iteration and is a class variable.

 

Mapping this outside the loop does not help the requirement, I guess. I need to connect a specific reply with an entry id, so I can match the entry with the corresponding response (QNetworkReply).

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QSignalMapper invokes slot multiple times

No, no, the Mapper object will get called multiple times if you connect the finished signal and the id will be passed into the mapper object and then a signal fired if there is a hit so moving it outside the loop will definately work.

 

Take a look at this example for what I mean...

 

 ButtonWidget::ButtonWidget(QStringList texts, QWidget *parent)
     : QWidget(parent)
 {
     signalMapper = new QSignalMapper(this);

     QGridLayout *gridLayout = new QGridLayout;
     for (int i = 0; i < texts.size(); ++i) {
         QPushButton *button = new QPushButton(texts[i]);
         connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
         signalMapper->setMapping(button, texts[i]);
         gridLayout->addWidget(button, i / 3, i % 3);
     }

     connect(signalMapper, SIGNAL(mapped(const QString &)),
             this, SIGNAL(clicked(const QString &)));

     setLayout(gridLayout);
 }

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: QSignalMapper invokes slot multiple times

The reason for getting multiple signals is that you've effectively set up 20-30 signalMapper connections and each of those will find the id and fire. You only need to set up the one.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
New Contributor
Posts: 8
Registered: ‎10-09-2013
My Device: Developer
My Carrier: none

Re: QSignalMapper invokes slot multiple times

Sweet ... you're absolutely right. Thank you very much!