In fact, this online has a lot of, write here, just give yourself a record, lest later find not full, or 1:30 will not find what they want. Keep up with the new ...
1. int, float, double turn into qstring
Method 1. Use Qstring::number ();
Long A = 63;
QString s = Qstring::number (A, 10); s = = "63"
QString t = Qstring::number (A, +). ToUpper (); t = = "3F"
Method 2. Use ARG ()
Long A = 63;
QString s = QString ("%1"). Arg (a);
This is handy for turning floating point numbers into qstring types.
2. Convert qstring to double type
Method 1. Using ToDouble ()
QString str= "123.45";
Double val=str.todouble (); val=123.45
Method 2. Very suitable for scientific counting method form Conversion
BOOL OK;
Double D;
D=qstring ("1234.56e-02"). ToDouble (&ok); ok=true;d;12.3456.
3. Convert the qstring to float
Method 1. Using Tofloat ()
QString str= "123.45";
float d=str.tofloat (); d=123.45
4. Convert the qstring shape to int
1. Converting to decimal shaping
Note: The cardinality defaults to 10. When the cardinality is 10 o'clock, and the cardinality must be between 2 and 36. If the cardinality is 0, if the string starts with 0x, it will be converted to 16, and if it starts with a 0, it is converted to octal, otherwise it will be converted to decimal.
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;
5. Long plastic conversion to qstring shape
Long A = 63;
QString Str=qstring::number (a,16); Str= "3f";
QString Str=qstring::number (a,16). ToUpper (); Str= "3F";
6. Qstring Conversion char*
Method One:
QString qstr ("Hello,word");
const char * p = qstr.tolocal8bit (). data ();
Method Two:
const char *p = qstr.tostdstring (). data ();
Some other conversion requirements:
convert current time to qstring ...
Public Qdatetime qdate = Qdatetime.currentdatetime ();
datetime = qdate.tostring ("yyyy mm month DD Day Ddddhh:mm:ss");
If not qtime and Qdate classes such as: How to convert a char unsigned char class received via 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);
}
Conversion between common data in QT