【问题标题】:QDebug string array display [duplicate]QDebug字符串数组显示[重复]
【发布时间】:2019-07-19 20:44:01
【问题描述】:

这是一个简单的domo:

string strList[4] = {"Blue", "Red", "Yellow"};
qDebug()<<"strList element : "<<strList[1];

error: C2678: binary '<<': no operator found which takes a left-hand operand of type 'QDebug' (or there is no acceptable conversion)

字符串显示有什么问题?

【问题讨论】:

    标签: string qt operators


    【解决方案1】:

    Qt 的调试模块无法识别“字符串”类。您需要使用 QString ,在这种情况下,您可能需要 QStringList (相当于 QList )。

    QStringList strList;
    strList << "Blue" << "Red" << "Yellow";
    qDebug() << "strList element : " << strList[1];
    

    【讨论】:

      【解决方案2】:

      qDebug 不接受字符串,但可以很好地处理“c-strings”

      而不是做:

      qDebug()<<"strList element : "<<strList[1];
      

      做:

      string strList[4] = {"Blue", "Red", "Yellow"};
      qDebug()<<"strList element : "<<strList[1].c_str();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-04
        • 1970-01-01
        • 1970-01-01
        • 2016-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多