zoukankan      html  css  js  c++  java
  • QString unsigned char* 的转换

    QString -> unsigned char* :
    QString str = "ABCD";
     int length = str.length();
    unsigned char* sequence = NULL;
    sequence =(unsigned char*)qstrdup(str.toAscii().constData());
    delete[] sequence;
    - sequence length = 5 --> ['A'] ['B'] ['C'] ['D'] ['/0']
    - sequence is now "independant" from str
    - sequence has to be deleted with -> delete [] sequence
    QString -> char:
    const QByteArray ba = string.toAscii(); // make ba const, because modifying this array might otherwise invalidate the pointer
    const char* sequence = ba.constData(); // now sequence will remain valid within the current scope.

    The call to toAscii() creates a temporary QByteArray which goes out of scope when used like this:
    char *sequence = string.toAscii().constData();
    // sequence is now a dangling pointer!

    http://wxpjiujiang.blog.163.com/blog/static/203994030201292661134137/

  • 相关阅读:
    求js数组中最小值
    分析apply,call方法
    前端模块化详解
    js中形参的小练习
    js中return返回值小练习
    mysql 视图
    mysql 数据库语句
    mysql 事务管理
    vue-前端工程化
    Vue-router
  • 原文地址:https://www.cnblogs.com/findumars/p/6124347.html
Copyright © 2011-2022 走看看