QString与各种类型互转

    //QString 转QByteArray
    QString qstr = "waixingren";
    qInfo(qstr.toLatin1().data());//waixingren
    QByteArray  qbyteArr = qstr.toLatin1();
    qInfo(qbyteArr);//waixingren
    //QByteArray转QString
    qbyteArr = "waixingren";
    qstr="";
    qstr.append(qbyteArr);//waixingren
    //QString转char*
    qstr="hello word!";
    const char *p = qstr.toLocal8Bit().data();
    //使用标准库中
    std::string str= qstr.toStdString();
    const char* ch = str.c_str();
    //char*转QString
    qstr = QString(QLatin1String(p));

 

你可能感兴趣的:(QT)