PDA

View Full Version : SIGNAL and SLOT



sophister
24th April 2009, 18:57
Hi, now I have to connect several SIGNALS to one SLOT, but how can I distinguish which QWidget emit the SIGNAL in the SLOT function??
Is there any way to find the sender??
Thanks !!

caduel
24th April 2009, 19:01
one way is QObject::sender()
other possibilities might be classes like QSignalMapper

sophister
24th April 2009, 19:18
Thanks!!
Could I ask you one more question?
when I use the QMap, something is always wrong. Following is my codes:
in the .h file :

QMap<QString, QToolButton*> buttons;
And I have added the declare at the beginning of the header file like this:

class QMap<QString, QToolButton*>;

But I just can't pass the compiler.

caduel
24th April 2009, 20:19
you need to write


#include <QMap>
#include <QString>
class QToolButton; // forward decl ok as you just use a ptr to it

sophister
25th April 2009, 06:02
Thank you !!
yeah, but I have forward declare for class QToolButton, and it's ok.
if I haven't include QMap, and just forward declare it using
class QToolButton;, the compiler will give some errors.
The only way to use QMap in the header file is to
#include <QMap>, while just using forward declare won't work.
I'm really puzzled

caduel
25th April 2009, 09:03
well, the compiler needs to know more here: QMap is a templated type.
If you write QMap, the compiler assumes QMap is a 'plain' type and then writing QMap<T1,T2> is not ok, just as you may not write QString<int>.