I am trying to use some vector data's name with struct
. I am trying to get see which name in qDebug()
To be more clear:
const std::string& testName = "asdfqwer";
qDebug() << testName;
It gives en error message in build:
Error: no match for 'operator<<' in 'qDebug()() << testName'
I don't have options to change const std::string&
type. Could you please help me to solve this issue without changing type?
qDebug()
does not know anything aboutstd::string
but it works withconst char*
. Appropriate operator you can find here. You can achieve this withdata()
or withc_str()
which is better asJiří Pospíšil
said.For example:
Aslo you can convert
std::string
toQString
with QString::fromStdString.If you need writing std::string to qDebug() often in your code, you can implement this function globally (for example in you
main.cpp
):