PDA

View Full Version : Many signals one slot



^Nisok^
17th April 2009, 13:17
Another newbie question.

Signals emittes from 5 pushbuttons have to be connected with one slot. But this slot must know from which pushbutton was activated. I already tried to do this:



slot (int i);
...
connect(push1, SIGNAL(clicked()),this, slot(1));

But doesn't work.
Any suggestions?

Lykurg
17th April 2009, 13:24
Have a look at QObject::sender().
MyClass::mySlot(){
if (sender() == myButton1)
{...}
}

wysota
17th April 2009, 13:50
Have a look at QSignalMapper.

^Nisok^
17th April 2009, 23:19
Thanks again. I used the mapping and I did it.
But this success led me to another different problem. I will continue to this thread.
Part of configdilog.h


private:
QLineEdit *ebmFloodImage,*ebmFloodImage20, *ebmCrystalEnergies, *ebmIMat, *ebmJMat;
QPushButton *psbFloodImage,*psbFloodImage20, *psbCrystalEnergies, *psbIMat, *psbJMat;
QString fl, fl20, ec, im, jm;
QSignalMapper *sm;
private slots:
void selectFile(const QString &);


And at the constructor I implement everything you see here. I connect the pushbuttons with the slot selectFile. But when I go to the slot and select a new file, I cannot "print" the new name to the lineEdits (from the slot routine, at the constructor I can set the Text). The following runtime error appears.



Program received signal SIGSEGV, Segmentation fault.
0x00007f7a0331b6f0 in QLineEdit::setText () from /usr/lib/libQtGui.so.4


Do have any idea where this comes from??

jpn
17th April 2009, 23:47
Probably you have a local variable in the constructor, instead of assigning to the member variable:


Type* var = new Something;
// vs.
var = new Something; // <-- should be like this

^Nisok^
18th April 2009, 10:52
Thanx, a lot! That was the problem. The statement that I had meant that I redeclare a new LineEdit and I don't use the global one?

jpn
18th April 2009, 11:51
One assigns to a new local variable, another assigns to the member variable. Member variables are not global variables. :)

^Nisok^
18th April 2009, 15:05
Yes... sorry.. idiot mistake...