QT:来自多个旋转框的项目列表
QT: list of item from multiple spinboxes
是否可以从每个旋转框中获取值列表并将它们放入列表中?
for (int i = 0; i < norm_size+1; i++){
getSpinleftValue(i);
}
我使用 for 循环来设置我的所有连接
.
void GuiTest::getSpinleftValue(int index){
QSpinBox* spinleft[norm_size+1] = {ui->norm_spinBox_9,
ui->norm_spinBox_10,
ui->norm_spinBox_11,
ui->norm_spinBox_12,
ui->norm_spinBox_13,
ui->norm_spinBox_14,
ui->norm_spinBox_15,
ui->norm_spinBox_16};
QObject::connect(spinleft[index], SIGNAL(valueChanged(int)), this, SLOT(spinboxWrite(int, index)));
}
.
然后,一旦 for 循环建立了连接,我想将它们的输出写入一个列表中以供以后使用。
.
void GuiTest::spinboxWrite(int arg1, int index){
int norm_list[16];
qDebug() << arg1;
qDebug() << index;
}
在这种情况下,我正在使用一些调试函数,以便查看它们是否正常工作。现在它看起来不起作用,因为我没有正确编写"连接"部分。
No such slot GuiTest::spinboxWrite(int, index) in
我知道另一种解决方案是创建一堆这些
void GuiTest::on_norm_spinBox_9_valueChanged(int arg1)
{
//code here
}
但是,如果我能帮助它,我宁愿不要用其中的 16 个污染我的整个文件!
信号valueChanged(int)
和插槽spinboxWrite(int, index)
(请注意,索引在您的情况下甚至不是一种类型!)没有匹配的签名,因此connect
不起作用。从文档中:
传递给 SIGNAL() 宏的签名的参数不得少于传递给 SLOT() 宏的签名。
我认为解决问题的最简单方法是将来自所有旋转盒的valueChanged(int)
信号连接到同一插槽,并使用sender
来获取已更改的旋转盒,以下是您在构造函数中执行此操作的方法:
GuiTest::GuiTest(QWidget* parent)/*do you initializations*/{
//after setup ui, create your spin boxes. . .
//get list of all children spin boxes
//(you can replace that with a hard coded list if it is
//not applicable)
QList<QSpinBox*> spinBoxes= findChildren<QSpinBox*>();
//connect the signal from all spin boxes to the slot
QSpinBox* spinBox;
foreach(spinBox, spinBoxes)
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(SpinBoxChanged(int)));
}
以下是您的spinboxWrite
槽的外观:
void GuiTest::SpinBoxChanged(int value){
QSpinBox* sp= qobject_cast<QSpinBox*>(sender());
//now sp is a pointer to the QSpinBox that emitted the valueChanged signal
//and value is its value after the change
//do whatever you want to do with them here. . .
}
相关文章:
- 从链接列表c++中删除一个项目
- 如何维护资源管理器项目视图中当前可见的项目列表
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 在给定的项目列表上实现搜索?
- 从文本文件读取,然后将项目存储到列表中
- 在修改项目列表时,请防止可编辑的Qcombobox选择更改
- 发送 QML 项目列表C++类连接到 QML :M16 错误
- 当SLIST_ENTRY不是项目列表的第一个成员时,使用单向链表
- 项目列表中的组合
- C ++ win 32,我想将项目列表添加到组合框中.我该怎么做
- 当试图在C++eclipse工作区中导出一个团队集(5个项目)时,项目列表是空的
- 随机化项目列表并将其输出到文本文件
- Eclipse CDT 自动更新/同步项目列表(以方便"refresh"相关项目集)
- 在每次迭代中以不同顺序循环遍历项目列表
- “添加到项目列表”是灰色的Qt项目管理对话框
- 从 std::vector<std::vector 中删除任意项目列表<T> >
- QT:来自多个旋转框的项目列表
- QComboBox动态项目列表
- QComboBox 不显示其项目列表
- 在浏览项目列表时保存多个项目的数据