How can I cast a QString to const char *??
I've tried QString::toStdString but it returns a std::string so if I can cast it to const char *... but I don't know how!
How can I cast a QString to const char *??
I've tried QString::toStdString but it returns a std::string so if I can cast it to const char *... but I don't know how!
You have to go through byte array. See docs for QString for transformations to byte array and then use QByteArray::constData() to go to const char *. Just make sure you either copy the data or store the byte array in a real variable if you want to use that pointer later on.
you can also use qPrintable it is equivalent to Wysota's suggestion.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
... but note that this is not merely a cast but a conversion. Also note that when the temporary objects (e.g. the std::string or the QByteArray) go out of scope the pointer returned gets invalid.
Bookmarks