如何转换QString为int? [英] How to convert QString to int?

查看:245
本文介绍了如何转换QString为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在来源中有一个 QString
所以我需要将其转换为整数而不使用Kb。

I have a QString in my sources. So I need to convert it to integer without "Kb".

我尝试了 Abcd.toInt (),但不起作用。

I tried Abcd.toInt() but it does not work.

QString Abcd = "123.5 Kb"


推荐答案

您的字符串中没有所有数字字符。所以你必须按空格拆分

You don't have all digit characters in your string. So you have to split by space

QString Abcd = "123.5 Kb";
Abcd.split(" ")[0].toInt(); //convert the first part to Int
Abcd.split(" ")[0].toDouble(); //convert the first part to double
Abcd.split(" ")[0].toFloat(); //convert the first part to float

这篇关于如何转换QString为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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