QDebug字符串数组显示

QDebug string array display

这是一个简单的 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)

字符串显示有什么问题?

Qt 的调试模块无法识别 "string" class。您需要使用 QString ,在这种情况下,您可能需要 QStringList (相当于 QList )。

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

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

而不是做:

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

做:

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