QObject::sender() in a Q_PRIVATE_SLOT

http://www.qtcentre.org/threads/31700-QObject-sender()-in-a-Q_PRIVATE_SLOT

 

 

class MyClassPrivate

{

public:

...

void _q_mySlot()

{

    Q_Q(MyClass); qDebug() << q->sender(); // should print "foo(0x.....)"

};

MyClass * const q_ptr;

Q_DECLARE_PUBLIC(MyClass);

};

 

class MyClass

{

Q_OBJECT

public:

MyClass(QObject *parent) : QObject(parent), d_ptr(new MyClassPrivate(this))

{

    connect(foo, SIGNAL(bar()), this, SLOT(_q_mySlot()));

};

private:

Q_DECLARE_PRIVATE(MyClass);

Q_PRIVATE_SLOT(d_func(), void _q_mySlot());

MyClassPrivate * const d_ptr;

};

把槽函数实现在MyClassPrivate 类中,用做MyClass内部使用的槽。

posted on 2011-11-04 15:12  katago  阅读(1736)  评论(0编辑  收藏  举报