Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未触发QCOMBOX信号_C++_Qt_Signals Slots - Fatal编程技术网

C++ 未触发QCOMBOX信号

C++ 未触发QCOMBOX信号,c++,qt,signals-slots,C++,Qt,Signals Slots,我已经检查了我的代码好几次,我仍然不明白为什么它不工作。 我使用一个连接到类中插槽的QComboBox,如下所示: this->choixCam = new QComboBox; this->choixCam->addItem("Camera 1"); this->choixCam->addItem("Camera 2"); this->choixCam->addItem("Camera 3"); this->choixCam->addIte

我已经检查了我的代码好几次,我仍然不明白为什么它不工作。 我使用一个连接到类中插槽的QComboBox,如下所示:

this->choixCam = new QComboBox;
this->choixCam->addItem("Camera 1");
this->choixCam->addItem("Camera 2");
this->choixCam->addItem("Camera 3");
this->choixCam->addItem("All cameras");
QObject::connect(this->choixCam, SIGNAL(currentIndexChanged(int)), this, SLOT(this->selectCam(int)));
代码的前一部分定义为我的类MainWindows的构造函数,在main中调用。头文件中的定义如下所示:

public:
    QComboBox* choixCam;
public slots:
    void selectCam(int choixCam);
我尝试通过另一个信号成功运行插槽

使用带有QString的信号,激活的信号(int)或尝试在网络上查找示例也不起作用。信号/插槽mecanism也适用于QButton和QSpinBox

我快没主意了。如果能帮上忙,我将不胜感激。
谢谢。

@eyllanesc答案应该有用。只需将
SLOT(this->selectCam(int))
更改为
SLOT(selectCam(int))

但是为什么QT不一样呢? 让我们看看connect方法:

QMetaObject::Connection QObject::connect(const QObject *sender, const char *signal,const QObject *receiver, const char *method,
Qt::ConnectionType type)
()

在信号和插槽定义处:

#define SLOT(a)     "1"#a
#define SIGNAL(a)   "2"#a
QT使用c字符串来识别QoObject的信号和插槽。 这些字符串在某种字典中用作所有QObject、signals和Slot的关键字。
只要尝试
std::cout检查
QObject::connect()
的结果,如果无法将信号连接到插槽,它可能是
false
。更改
QObject::connect(this->choixCam,SIGNAL(currentIndexChanged(int)),this,slot(this->selectCam(int))
QObject::连接(此->choixCam,信号(currentIndexChanged(int)),此,插槽(选择CAM(int)),是否输入错误?谢谢。使用新样式:
connect(this->choixCam,&QComboBox::currentinexchanged,this,&main窗口::selectCam)
FYI:
QObject:
不需要<代码>QMainWindow
继承自
QObject
connect(this->choixCam, "2currentIndexChanged(int)", this, "1selectCam(int)");