使用数据库中的数据自动填充 QComboBox

发布于 2024-09-13 17:48:13 字数 300 浏览 2 评论 0 原文

我创建了一个 QComboBox 委托,用于 QTableView 的单列(该列的每个单元格都是一个单独的组合框),我想要在 combobox 中显示的数据从数据库返回,作为由 ; 分隔的 id 字符串;
我的问题是,如何使用数据库检索到的数据填充我的组合框。

澄清一下:有问题的列检索特定的 Id(4 位数字字符串),有时一个对象可能有多个 Id(用 ; 分隔),我想创建一个 combobox具有多个 ID 的单元格,以便用户可以选择他们想要使用的一个。

I have created a QComboBox delegate which I use for a single column of a QTableView (each cell of that column is an individual combobox), the data which I want to display in my combobox returns from the database as a string of id's separated by a ;
My question is, how do I populate my combobox with this data retrieved by the database.

To clarify: the column in question retrieves specific Id's (4 digit strings), sometimes an object may have multiple Id's (separated by ;), I want to create a combobox for the cells with multiple Id's so the user can select which one they want to work with.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_蜘蛛 2024-09-20 17:48:13

也许这样的事情会起作用:

  QString data = "Id01;Id02;Id03;Id04;Id05";
  QStringList list = data.split(";");

  QComboBox *comboBox = new QComboBox;
  comboBox->insertItems(0, list);

Perhaps something like this would work:

  QString data = "Id01;Id02;Id03;Id04;Id05";
  QStringList list = data.split(";");

  QComboBox *comboBox = new QComboBox;
  comboBox->insertItems(0, list);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文