qt 类型转换相关

  • 8/16进制QString转换成int类,

    int QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const
    If base is 0, the C language convention is used: If the string begins with “0x”, base 16 is used; if the string begins with “0”, base 8 is used; otherwise, base 10 is used.

    所以在toInt时只要把base设为0,直接使用c格式的类型转换就行了.“0x11”=“021”=“17”

  • QString 转换为char* ,const char* , char

    char *QByteArray::data()
    看示例如下:
    QString tmp = “test”;
    QByteArray text = tmp.toLocal8Bit();
    char *data = new char[text.size() + 1];
    strcpy(data, text.data());
    delete [] data;
    所以只需先转换成QByteArray类型再用data()方法就行,转换成char型,只要QByteArray.at(0)就行,变化很多不只这种.

  • int ,float ,double to Qstring

    QString::setNum(T a,int base)
    QString QString::arg(T a, int fieldWidth = 0, int base = 10, QChar fillChar = QLatin1Char( ’ ’ )) const

  • QImage获取像素首址 uchar* 类型

    uchar *QImage::bits()
    Returns a pointer to the first pixel data. This is equivalent to scanLine(0).

  • 重载函数信号的类型指明,多用于信号槽连接
    1.static_cast<T*>(a)
    2. qOverload<T*>(a) ,5.7以后可用
    eg:

    #if ( QT_VERSION >= QT_VERSION_CHECK(5,7,0) )
        connect(input, QOverload<const QString &>::of(&QComboBox::activated) \
        ,[&](const QString text){
    		//todo
        });
    #else
        connect(input, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated)\
        ,[&](const QString text){
    		//todo
        });
    #endif
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值