How can I connect signals and slots of different objects in Qt?

China☆狼群 提交于 2019-12-01 21:08:09

You connect signals and slots of instances, not of classes.

You need the address of both the receiver and the emitter objects to connect them together.

connect(button, SIGNAL(clicked()),
        pointer_to_instance_of_head, SLOT(change_number()));

(assuming "button" is a pointer).

Getting that pointer is another question, but unless you don't have a good reason to do otherwise, I suggest constructing the head object in the constructor of the QWidget you are deriving.

Well, assuming everything is as simple as you show it your really really abbriated code, it should be simple

connect( aTailInstance->tailButon, SIGNAL( clicked() ), aHeadInstance, SLOT( change_number() ) );

However, with the code you have shown here it is impossible to determine what kind of functionality you are after and it isn't clear exactly what you are asking.

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