c++ - QInputDialog 操作取决于 ComboBox 中的项目选择

标签 c++ qt events user-interface dialog

我有一个输入对话框 (Qt),在一个组合框中包含三个选项。我想根据在组合框中选择的项目在 Ok 上启动不同的操作。现在,我有

QInputDialog qDialog ;

QStringList items;
items << QString("Choice 1");
items << QString("Choice 2");
items << QString("Choice 3");

qDialog.setOptions(QInputDialog::UseListViewForComboBoxItems);
qDialog.setComboBoxItems(items);
qDialog.setWindowTitle("Choose action");

QObject::connect(&qDialog, SIGNAL(textValueChanged(const QString &)), 
           this, SLOT(onCompute(const QString &)));

qDialog.exec();

插槽 oncompute 根据组合框中的所选项目执行不同的操作...但是当用户在框中选择新项目时调用它,而不是在单击确定时调用。

如何检索在组合框中选择的项目并在单击“确定”时执行操作?

最佳答案

用信号 textValueSelected 替换 textValueChanged 就成功了。

关于c++ - QInputDialog 操作取决于 ComboBox 中的项目选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26376341/

相关文章:

c++ - 为什么我们需要维护自己的矩阵来转换 Game 对象?

c++ - 如何从 HMENU 获取菜单 ID?

qt - 如何去掉QScrollbar滚动按钮?

events - 在 Angular v2 中处理来自 Google Charts 的选择事件

javascript - React 如何使用 typescript 处理复选框的选中和未选中事件

c++ - 如何在 cmake 中使用 COMPONENTS 配置项目

c++ - dlib 的 scan_fhog_pyramid : set max_pyramid_levels

c++ - Qt 避免循环依赖

Qt Translation 返回相同的字符串而不是翻译

javascript - js_of_ocaml 和 event_listener