QT - 如何获取信号“currentIndexChanged”来自 QVector
我想从选定的 QComboBox 中获取 QString 文本。当我在 QComboBox 上选择一个索引时,在单击 QcomboBox 上所需的索引后,我想从所选索引中获取 QString。
我对此进行了研究,
但还没有找到解决方法,
QVector<QComboBox*> cboxes;
for (int i =0; i< 40 ; i++)
{
QComboBox *box = new QComboBox();
cboxes.append(box);
}
for(int i = 0; i < 40; i++)
{
connect(cboxes[i], SIGNAL(currentIndexChanged(const QString &text)), this, SLOT(comboBoxAdjusted_Changed(QString)));
}
comboBoxAdjusted_Changed 函数
void DialogSettings::comboBoxAdjusted_Changed(QString text)
{
std::cout << text.toStdString() << endl;
}
我尝试过,但是每次我更改组合框索引时,它都不会给出输出。
for (int i =0; i< 40 ; i++)
{
connect(cboxes[i], static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
[=](const QString &text){
std::cout << text.toStdString() << endl;
});
我应该怎么办?
I want to get QString text from selected QComboBox. When I selected an index on a QComboBox, I want to get QString from the selected index, after I clicked the desired index on a QcomboBox.
I have researched about this,
but have not found a way to solve it,
QVector<QComboBox*> cboxes;
for (int i =0; i< 40 ; i++)
{
QComboBox *box = new QComboBox();
cboxes.append(box);
}
for(int i = 0; i < 40; i++)
{
connect(cboxes[i], SIGNAL(currentIndexChanged(const QString &text)), this, SLOT(comboBoxAdjusted_Changed(QString)));
}
comboBoxAdjusted_Changed function
void DialogSettings::comboBoxAdjusted_Changed(QString text)
{
std::cout << text.toStdString() << endl;
}
I have Try, but everytime i change the combobox index, It isn't give output.
for (int i =0; i< 40 ; i++)
{
connect(cboxes[i], static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
[=](const QString &text){
std::cout << text.toStdString() << endl;
});
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到信号语法缺少函数输入参数。
以下是
currentIndexChanged
的两个有效信号,如果您必须处理
index
,请根据您的情况尝试以下操作。I see signal syntax is missing the function input argument.
Below are two valid signals for
currentIndexChanged
If you have to handle
index
try below for your case.