我正在使用qt 5.2.我的连接功能的来电:
QObject::connect(ui->mycombobox, SIGNAL(activated(0)), ui->mypushbutton, SLOT(toggle()));
// When I select first element from mycombobox, mypushbutton must be disabled
Run Code Online (Sandbox Code Playgroud)
程序打印:
QObject::connect: No such signal QComboBox::activated(0) in <myfile>
Run Code Online (Sandbox Code Playgroud)
您尝试使用的信号被激活(int),我不知道您为什么要尝试连接激活(0).它应该是这样的:
QObject::connect(ui->mycombobox, SIGNAL(activated(int)), ui->mypushbutton, SLOT(toggle()));
Run Code Online (Sandbox Code Playgroud)
如果要使用项索引过滤操作,则应将参数传递给插槽,并执行特定操作,例如:
QObject::connect(ui->mycombobox, SIGNAL(activated(int)), this, SLOT(mySlot(int)));
/*...*/
void MyClass::mySlot(int arg)
{
if(arg == 0)
ui->mypushbutton.toggle();
}
Run Code Online (Sandbox Code Playgroud)