Qt - 如何测试 QTableWidget 项的文本是否为整数
Qt - How to test whether the text of QTableWidget item is an integer number or not not?
我正在使用Qt和C++。如果我有QTableWidget
,如何测试项目的文本是否为整数?
if(table->item(index, 0)->text().is_integer())
Qdebug("yes is an integer") ;
else
Qdebug("no is not an integer") ;
你这样做就像你做通常的QString
来int
转换 - QString::toInt
,但你可以忽略返回值。我建议使用这个辅助函数,因为它可以让您了解成功/失败QString::toInt
:
bool isInt(QString const& str, int base = 10)
{
bool ok = false;
str.toInt(&ok, base);
return ok;
}
用法:
if(isInt(table->item(indice, 0)->text()))
...
编辑:我不知道为什么我在这里使用toInt
。如果有较大的数字只能用较大的整数数据类型表示(或者您只想处理unsigned
数字),请为这些数字创建此函数。
相关文章:
- 如何将 UTF-8 文本从文件转换为某个可以迭代的容器,并检查每个符号是否为C++字母数字?
- 是否可以在文本文件中找到最长单词的长度,并在同一个文本文件中读取,只需 1 个 while 循环?
- 返回从字符串文本创建的静态string_view是否安全?
- 是否保证相同内容字符串文本的存储相同?
- 是否可以创建一个用户定义的文本,将字符串文本转换为 own 类型的数组?
- 是否可以在原始字符串文本中插入转义序列?
- 如何知道文本文件中的输入是否是 C++ 中的有效数字
- 如何检查字符串格式在读取C++文本文件时是否有效?
- 是否可以在运行时调用用于选择要调用的用户定义文本的逻辑?
- 在现代C++中是否可以将字符串文本作为参数传递给C++模板?
- 标准是否阻止在可变参数模板中使用足够小的文本值缩小文本转换范围
- 是否可以在多行字符串文本中使用 C/C++ 预处理器令牌
- 是否有提供可调整 dpi、可选文本和 CSS 支持的 HTML 到 PDF 渲染器?
- C++是否可以将宏重写浮点文本为双文本或至少删除 f 后缀?
- 从文本文件读取时,如何知道是否已到达新行?
- (Qt)如何检查 QTextEdit 小部件文本是否已从 QTabWidget 更改
- Qt - 如何测试 QTableWidget 项的文本是否为整数
- 以十进制、八进制和十六进制表示法标识整数文本是否与转义字符中的整数文本相同
- 如何判断LPCWSTR文本是否为数字
- 如何确定CRichEditCtrl中所选文本是否具有多种字体大小