개발/Qt

[Qt] QString을 Char*로 변경하는 방법

LifeCoding 2022. 1. 15. 22:07

방법 1. toStdString().c_str() 사용

QString text = "AAA";
const char* p = text.toStdString().c_str();
qDebug("text : %s", p);

이는 아래 코드와 동일하다.

QString text = "AAA";
std::string str = text.toStdString();
const char* p = str.c_str();
qDebug("text : %s", p);

방법 2. qPrintable() 사용

QString text = "AAA";
qDebug("text : %s", qPrintable(text));