QT使用信号槽机制传递参数

1、当我们需要使用一个函数中的变量而又不想把这个变量设置为全局时,除了把它作为函数返回值ruturn出来,我们还可以使用信号来传递。

当参数数量相同时:
信号: void singal(Qstring str) 槽函数: void mainwindow::slot(Qstring str)

绑定: connect(this, SIGNAL(singal(Qstring)), this, SLOT(slot(Qstring)));

发送信号: emit(singal(“hello world!”));

当参数数量不同时 :
只能是信号的参数数量多于槽函数的参数数量,且前面相同数量的参数类型应一致,信号中多余的参数会被忽略。
信号: void singal(Qstring str,int a,double b)

槽函数: void mainwindow::slot(Qstring str,int a)

绑定: connect(this, SIGNAL(singal(Qstring,int,double)), this, SLOT(slot(Qstring,int)));

发送信号: emit(singal(“hello world!”,4));

发布了29 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_42542969/article/details/88994107
今日推荐