There are several ways one can initialize a QString, including constructing it directly from a char array.
To go back from a QString to a char array, one easy way would be to convert it to a std::string
, using the method QString::toStdString() and then to a char array using the method std::string::c_str().
For example:
#include <QString>
#include <cstring>
#include <cassert>
int main()
{
char str1[] = "abc";
QString qString = str1;
char const* str2 = qString.toStdString().c_str();
assert(std::strcmp(str1, str2) == 0);
return 0;
}
Note however this simple example assumes UTF-8 encoding. Please go through the reference manual which I linked here for a more detailed description of QString.