Qt-solutions Archive, September 2006
Signals: fixed slot parameter
Message 1 in thread
Hi Everyone,
my questions is probably an FAQ, however, I could not find the solution,
yet. Reference to helpful documentation is highly welcome.
I have multiple QLabels which send signals to an upper layer:
connect(sliceImg[0], SIGNAL(mouseClick(int,int)), this, SLOT(click0(int,int)));
connect(sliceImg[1], SIGNAL(mouseClick(int,int)), this, SLOT(click1(int,int)));
where they are fed to a common function:
void click0(int x, int y) { clickMouse(0,x,y); }
void click1(int x, int y) { clickMouse(1,x,y); }
It works, however, I would prefer to avoid the helper functions clickX
and instead just do something like this:
for (int i=0; i<X; ++i)
connect(sliceImg[i], SIGNAL(mouseClick(int,int)),
this, SLOT(clickMouse(i,int,int)));
Using a fixed slot parameter. However, this only yields a
No such slot QSliceViewer::clickMouse(i,int,int)
The QSignalMapper is (as far as I understood it) no solution, since I my
QLabels are not identifiable as the QPushButtons in the QSignalMapper
example. I could, however, tell them their id and emit this with the
signal. But, is this the cleanest solution?
I am currently working with Qt-4.1.4.
Best regards,
Christian
--
[ signature omitted ]
Message 2 in thread
Christian Lackas schrieb:
> Hi Everyone,
>
> my questions is probably an FAQ, however, I could not find the solution,
> yet.
Yes, it is. Use QSignalMapper.
> The QSignalMapper is (as far as I understood it) no solution, since I my
> QLabels are not identifiable as the QPushButtons in the QSignalMapper
> example. I could, however, tell them their id and emit this with the
> signal. But, is this the cleanest solution?
Either I misunderstood your problem, or you didn't read the
QSignalMapper docs thoroughly. You announce the IDs of your widgets with
connecting your widget's signals to the mapper's slots. No need to emit
them with your signal.
BTW, though this list is named "qt-solutions", this doesn't refer to
getting solutions for all Qt related problems, but to the (commercial)
product Qt Solutions. Please use qt-interest for everything related to
the main Qt package.
Martin
--
[ signature omitted ]