将信号和槽关联到qcheckbox动态创建 [英] Associate signal and slot to a qcheckbox create dynamically
问题描述
我有一个非常具体的问题,所以我要尽可能的清楚。
I've got a very specific problem so I'm going to try to be as clear as possible.
我有一个 QTableWidget
其中包含 QTableWidget
,我的 QTableWidget
的每一行都是动态创建的,文件。
I've got a QTabWidget
which contains QTableWidget
, every line of my QTableWidget
is create dynamically by reading a file.
正如你所看到的,当我创建一个行时,我在末尾添加一个 qCheckBox
。我现在的目标是,当我点击我的 QtableTab
的最后一个标签中的 QTableWidget
qCheckBox
(当我取消选中 qCheckBox
时,删除此行)。
As you may see, when I create a line, I add a qCheckBox
at the end. My goal now, is to send this line to the QTableWidget
in the last tab of my QtableTab
when I click on the qCheckBox
( and to delete this line when I uncheck the qCheckBox
).
所以每次动态创建一行时,我试着关联到 qCheckBox
一个信号:
So every time I create a line dynamically, I try to associate to my qCheckBox
a signal :
QObject::connect(pCheckBox, SIGNAL(clicked()), this, SLOT(cliqueCheckBox(monTab,ligne, pCheckBox)));
但它不工作,我有错误:
But it won't work, I've got the error :
QObject::connect: No such slot supervision::cliqueCheckBox(monTab,ligne, pCheckBox)
但是这个槽存在,我在我的头文件和我的cpp中声明这样:
But this slot exist, I declare it in my header file and my cpp like this :
void supervision::cliqueCheckBox(QTableWidget *monTab, int ligne, QCheckBox *pCheckBox)
我的解决这个问题的方法是好吗?如果是,如何正确关联信号到插槽,如果否,如何继续?
Is my way to procced for solving this problem is good ? If yes how to correctly associate the signal to a slot, and if no, how to proceed ?
谢谢。
:下面是我的函数创建 qCheckBox
并动态关联的代码:
: Here's the code of my function creating the qCheckBox
and associated it dynamically :
void supervision::ajouterCheckBox(QTableWidget *monTab, int ligne){
// Creation de la check box
QWidget *pWidget = new QWidget(); //Creation du widget contenant la checkbox
QCheckBox *pCheckBox = new QCheckBox(); // Creation de la checkbox
QHBoxLayout *pLayout = new QHBoxLayout(pWidget); // Layout pour centrer ma checkbox
pLayout->addWidget(pCheckBox); // Ajout de la check box au layout
pLayout->setAlignment(Qt::AlignCenter); //Alignement
pLayout->setContentsMargins(0,0,0,0);//Supression des bordure
pWidget->setLayout(pLayout);//Mise en place du layout dans le widget
monTab->setCellWidget(ligne,5,pWidget);//Mise en place du widget contenant la checkbox dans ça cellule
//Mise en place de la connection
QObject::connect(pCheckBox, SIGNAL(clicked()), this, SLOT(cliqueCheckBox(monTab,ligne, pCheckBox)));
}
推荐答案
$ c> SIGNAL(clicked())到 SLOT(cliqueCheckBox(monTab,ligne,pCheckBox)
You are connecting SIGNAL(clicked())
to SLOT(cliqueCheckBox(monTab,ligne, pCheckBox)
which is invalid. The arguments of the signal and slot should match. Here you don'y provide any parameters for the target slot.
正确的格式是:
QObject::connect(pCheckBox, SIGNAL(clicked()), this, SLOT(clickedCheckBox()));
并且 clickedCheckBox
插槽应该可以访问小部件的指针:
And clickedCheckBox
slot should have access to the pointers of your widgets :
void myClass::clickedCheckBox()
{
...
}
这篇关于将信号和槽关联到qcheckbox动态创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!