Convert QString to double type
Method 1: QString str = "123.45 ";
Double val = str. toDouble (); /// val = 123.45
Method 2. Suitable for scientific notation form conversion
Bool OK;
Double d;
D = QString ("1234.56e-02"). toDouble (& OK); // OK = true; d; 12.3456.
Convert QString to float
1. QString string str = "123.45 ";
Float d = str. toFloat (); // d = 123.45
2. QString str = "R2D2 ";
Bool OK;
Float d = str. toFloat (& OK); // If the conversion is successful, 0.0 is returned. OK = false;
Convert QString to integer
1. Convert to decimal integer
Note: The default base is 10. When the base number is 10, and the base number must be between 2 and 36
. If the base number is 0, if the string starts with 0x, it is converted to hexadecimal notation. If it starts with 0, it is converted to octal notation. Otherwise, it is converted to decimal notation.
Qstring str = "FF ";
Bool OK;
Int dec = str. toInt (& OK, 10); // dec = 255; OK = rue
Int hex = str. toInt (& OK, 16); // hex = 255; OK = true;
3. Convert regular integer to Qstring
Long a = 63;
QString str = QString: number (a, 16); // str = "3f ";
QString str = QString: number (a, 16). toUpper (); // str = "3F ";
Qstring conversion char * problem!
Method 1:
QString qstr ("hello, word ");
Const char * p = qstr. toLocal8Bit (). data ();
Method 2:
Const char * p = qstr. toStdString (). data ();
The converted constant
Convert the current time to QString...
Public QDateTime qdate = QDateTime. currentDateTime ();
Datetime = qdate. toString ("yyyy-MM-dd ddddhh: mm: ss ");
If it is not a QTime or QDate class, for example, how to convert the char unsigned char class received through TCP/IP to a QString class?
QString Time2String (DWORD dwTime)
{
Char ctime [50] = {0 };
Memset (ctime, 0, 50 );
Strftime (ctime, 32, "% Y-% m-% d % H: % m: % s", localtime (& time_t (dwtime )));
Return qstring (ctime );
}
From: http://blog.163.com/zjf_to/blog/static/2014290612011112883629518/