本文介绍了QSignalMapper如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的帖子后:我需要关联:



•信号 clicked()当我点击 qCheckBox 到我的函数 cliqueCheckBox(QTableWidget * monTab,int ligne,QCheckBox * pCheckBox)为了这样做,我必须使用 QSignalMapper ,经过两个小时的努力来了解它是如何工作,我可以'我有一个很好的结果,这里是我所做的代码,这显然是错误的:

  QSignalMapper * m_sigmapper = new QSignalMapper ; 
QObject :: connect(pCheckBox,SIGNAL(mapped(QTableWidget *,int,QCheckBox *)),pCheckBox,SIGNAL(clicked
QObject :: connect(this,SIGNAL(clicked()),this,SLOT(cliqueCheckBox(QTableWidget * monTab,int ligne,QCheckBox * pCheckBox)));

m_sigmapper-> setMapping(pCheckBox,(monTab,ligne,pCheckBox));
QObject :: connect(m_sigmapper,SIGNAL(clicked()),this,SLOT(cliqueCheckBox(QTableWidget * monTab,int ligne,QCheckBox * pCheckBox)));你可以向我解释一下,如何 QSignalMapper


$ b

解决方案

QSignalMapper 类收集一组无参数信号,并使用与发送信号的对象相对应的整数,字符串或窗口小部件参数重新发射它们。因此,您可以有一个:

  QSignalMapper * mapper = new QSignalMapper(this); 
QObject :: connect(mapper,SIGNAL(QWidget *)),this,SLOT(mySlot ));

对于每个按钮,您可以连接 信号到 map()插槽 QSignalMapper 并使用setMapping添加映射当从一个按钮发出 clicked()时,发出信号映射(QWidget *)

  QPushButton * but = new QPushButton(this); 

QObject :: connect ),mapper,SLOT(map()));
mapper-> setMapping(but,but);


b $ b

这种方式每当你点击一个按钮,映射器的映射(QWidget *)信号发射包含窗口小部件作为参数。


After my post here : Associate signal and slot to a qcheckbox create dynamically I need to associate :

• The signal clicked() when I click on a qCheckBox to my function cliqueCheckBox(QTableWidget *monTab, int ligne, QCheckBox *pCheckBox)

To do so, I have to use QSignalMapper, after two hours of trying to understand how it works, I can't have a good result, here's the code I make, this is obviously wrong :

 QSignalMapper *m_sigmapper = new QSignalMapper(this);
 QObject::connect(pCheckBox, SIGNAL(mapped(QTableWidget*,int, QCheckBox*)), pCheckBox, SIGNAL(clicked()));
 QObject::connect(this, SIGNAL(clicked()), this, SLOT(cliqueCheckBox(QTableWidget *monTab, int ligne, QCheckBox *pCheckBox)));

 m_sigmapper->setMapping(pCheckBox, (monTab,ligne, pCheckBox));
 QObject::connect(m_sigmapper, SIGNAL(clicked()),this, SLOT(cliqueCheckBox(QTableWidget *monTab, int ligne, QCheckBox *pCheckBox)));

Can you explain to me, how QSignalMapper works ? I don't really understand what to associate with :(

解决方案

QSignalMapper class collects a set of parameterless signals, and re-emits them with integer, string or widget parameters corresponding to the object that sent the signal. So you can have one like:

QSignalMapper * mapper = new QSignalMapper(this);
QObject::connect(mapper,SIGNAL(mapped(QWidget *)),this,SLOT(mySlot(QWidget *)));

For each of your buttons you can connect the clicked() signal to the map() slot of QSignalMapper and add a mapping using setMapping so that when clicked() is signaled from a button, the signal mapped(QWidget *) is emitted:

QPushButton * but = new QPushButton(this);

QObject::connect(but, SIGNAL(clicked()),mapper,SLOT(map()));
mapper->setMapping(but, but);

This way whenever you click a button, the mapped(QWidget *) signal of the mapper is emitted containing the widget as a parameter.

这篇关于QSignalMapper如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:11