如何在Qt中使用GUI对象名称运行循环? [英] How to run a loop using gui object names in qt?

查看:61
本文介绍了如何在Qt中使用GUI对象名称运行循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gui表单,其中存在多个文本框.我想将它们的值放入数组中.做到这一点的一种方法是编写类似

I have a gui form, where multiple text boxes are present. I want to put their values inside an array. One way of doing it is by writing something like this

{array element } = ui->text_1->text();

并重复它,直到text_2,text_3直到n.

and repeat it for text_2,text_3 upto n.

我想要的是运行一个循环,并在每个循环中替换文本框名称的数字部分.

What I want is to run a loop and replace number portion of text box name in each cycle.

类似这样的 {array element} = ui-> text_ {此数字已更改}-> text();

如何在qt中完成?

推荐答案

列出的另一个选择是使用初始化列表创建数组.根据数组的大小(以及更改的频率),这可能是可行的.

Another option to those listed would be to create an array using an initializer list. Depending on how big the array is (and how often it changes), this might be workable.

QLineEdit* entries[] = { ui->text_0, ui->text_1, ui=>text_2 };
QStringList answers;
for ( int i = 0; i < 3; ++i )
{
    answers += entries[i]->text();
}

这篇关于如何在Qt中使用GUI对象名称运行循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆