Qt C++ QString to QByteArray Conversion

I guess you should use: QString::fromUtf8(const QByteArray &str) Or: QString::QString(const QByteArray &ba) to convert QByteArray to QString, then write it into file by QTextStream. After that, read file by QTextStream, use: QString::toUtf8() to convert QString to QByteArray. QString::QString(const QByteArray &ba) Constructs a string initialized with the byte array ba. The given byte array is converted … Read more

switch/case statement in C++ with a QString type

You can, creating an QStringList before iteration, like this: QStringList myOptions; myOptions << “goLogin” << “goAway” << “goRegister”; /* goLogin = 0 goAway = 1 goRegister = 2 */ Then: switch(myOptions.indexOf(“goRegister”)){ case 0: // go to login… break; case 1: // go away… break; case 2: //Go to Register… break; default: … break; }

How to convert a QJsonObject to QString

Remembering when I first needed to do this, the documentation can be a bit lacking and assumes you have knowledge of other QJson classes. To obtain a QString of a QJsonObject, you need to use the QJsonDocument class, like this: – QJsonObject jsonObj; // assume this has been populated with Json data QJsonDocument doc(jsonObj); QString … Read more

How to convert QString to int?

You don’t have all digit characters in your string. So you have to split by space QString Abcd = “123.5 Kb”; Abcd.split(” “)[0].toInt(); //convert the first part to Int Abcd.split(” “)[0].toDouble(); //convert the first part to double Abcd.split(” “)[0].toFloat(); //convert the first part to float Update: I am updating an old answer. That was a … Read more

Qt. get part of QString

If you do not need to modify the substring, then you can use QStringRef. The QStringRef class is a read only wrapper around an existing QString that references a substring within the existing string. This gives much better performance than creating a new QString object to contain the sub-string. E.g. QString myString(“This is a string”); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)