how to pass qobject as argument from signal to slot in qt connect

邮差的信 提交于 2019-12-03 03:30:45

Usually QObject is passed by pointer, not by reference (note that QObject cannot be copied and cannot be passed by value). QObject* is registered as a meta type by default. So creating a signal and a slot with QObject* argument is enough to get them work:

private slots:
  void test_slot(QObject* object);

signals:
  void test_signal(QObject* object);

Initialization:

connect(this, SIGNAL(test_signal(QObject*)), this, SLOT(test_slot(QObject*)));

Emitting:

QObject* object = new QObject();
emit test_signal(object);

Of course the signal and the slot could be in different classes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!