如何提取我的spinBox的名称?我尝试查看了许多文档,但是找不到任何可以显示每个子spinBox名称的东西。我尝试将结果更改为字符串。但是,我只得到了我想像的地址的十六进制或长整数,而是返回了。 QList<QSpinBox*> spinBoxes= findChildren<QSpinBox*>(); //create the QSignalMapper object QSignalMapper* signalMapper= new QSignalMapper(this); //loop through your spinboxes list QSpinBox* spinBox; foreach(spinBox, spinBoxes){ //setup mapping for each spin box connect(spinBox, SIGNAL(valueChanged(int)), signalMapper, SLOT(map())); signalMapper->setMapping(spinBox, spinBox); } //connect the unified mapped(QWidget*) signal to your spinboxWrite slot connect(signalMapper, SIGNAL(mapped(QWidget*)), this, SLOT(spinboxWrite(QWidget*)));...void GuiTest::SpinBoxChanged(QWidget* wSp){ QSpinBox* sp= (QSpinBox*)wSp; //now sp is a pointer to the QSpinBox that emitted the valueChanged signal int value = sp->value(); //and value is its value after the change //do whatever you want to do with them here. . . qDebug() << value << "SpinBoxChanged";}void GuiTest::spinboxWrite(QWidget* e){ SpinBoxChanged(e); QString* value = (QString*)e; qDebug() << e << value << " SpinBoxWrite";}请注意 qDebug(),因为这是我在获取有关Spinboxes的某些信息时遇到的问题 最佳答案 您尝试检索的名称是 objectName 属性,每个QObject和QObject派生类都具有该属性。调用objectName()检索此值。您也可以将其与 QObject::findChild() 函数一起使用。这应该得到您想要的:void GuiTest::spinboxWrite(QWidget* e){ SpinBoxChanged(e); qDebug() << e->objectName() << " SpinBoxWrite";并将输出: "norm_spinBox_10" SpinBoxWrite 注意这行很危险:QSpinBox* sp= (QSpinBox*)wSp;使用 qobject_cast 而不是C样式强制转换。关于c++ - 我想在Qt中获取我的旋转框的名称,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38275051/ 10-11 02:52