Solved Converting QString to const char* ?
-
I need to convert QString to const char* reliably so I can use lua_pushstring() which only takes const char* as an argument. Is there a way to do this?
thestring.toStdString().c_str() /// Also doing this breaks the string and returns this unknown □ thing in place of the actual string.
Or alternatively is there a way to display std::strings on UIs instead of QString?
-
Hi,
@part-time-roadman said in Converting QString to const char* ?:
thestring.toStdString().c_str() /// Also doing this breaks the string and returns this unknown □ thing in place of the actual string.
You are taking the address of the first char of the temporary std::string returned by toStdString. Store the result of toStdString and then use that.
You can convert your std::string to QString for the UI part.
-
@part-time-roadman said in Converting QString to const char* ?:
Or alternatively is there a way to display std::strings on UIs instead of QString?
Which UIs?
What is your use case actually?
You can always convert std::string to QString.How to convert QString to char* depends on ecoding of your QString.
Take a look at various QString::to*() methods. -
Alright how would I convert std::string to QString?
-
@part-time-roadman Easy to find in the documentation: https://doc.qt.io/qt-5/qstring.html#fromStdString