C++&Qt 各种数据类型转换

7 篇文章 0 订阅

1.uint64转QString

QString strfilerename = QString("%1").arg(nFileID); //nFileID为uint64类型

QString::number( nFileID);

2.QString转超长数字串

QString a=123456789012345;

uint64 nB = a.toULongLong();

3.uint64_t 转std::string

std::to_string(nFileID); //nFileID为uint64_t类型

4.std::string 转 uint64_t(或unsigned)

unsigned long      strtoul( const char *str, char **str_end, int base );

unsigned long long strtoull( const char *str, char **str_end, int base );

std::string SuccessDataName;

uint64_t  unJobID = std::strtoull(SuccessDataName.c_str(), NULL, 10);

//base 的合法集是 {0,2,3,...,36};base为 ​0​ ,则自动检测数值进制:若前缀为 0 ,则底为八进制(可参考八进制表示方法),若前缀为 0x0X ,则底为十六进制,否则底为十进制。

5.QString与Std::String

QString strFilePath=QString::fromStdString(strFileDirectory); //strFileDirectory为Std::String类型

Std::String strFileDirectory=strFilePath.tostdString();//strFilePath为QString类型。

6.内存数据转换为输入流

 需要添加头文件

#include <strstream>
using namespace std;

//假设pData指向了内存中你想要转变为流的数据
//iLen是数据长度
strstreambuf buff(pData, iLen);
istream xmlStream(&buff);  //xmlStream也就是你要的流了
 

 7. QDateTime 转QString

#include <QDateTime> 

QDateTime  tEstimatedTime;

f (tEstimatedTime.toSecsSinceEpoch() == 0)
{
         return " ";
}
else
{
         return tEstimatedTime.toString("yyyy/M/d HH:mm:ss");
}

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值