Id=dateline->text ();//Get string
QString str = ID;
BOOL OK;
int hex = Str.toint (&ok, +); Turns a string into a 16-mechanism number
hex=hex+1;
QString t = qstring::number (hex, +). ToUpper (); Turns a number into a 16 mechanism and displays it in uppercase
Dateline->settext (t); shown in Textveiw ()
cout<< hex<<endl;
16 binary conversion.
This is a very classic code, mainly used in string and int type conversion.
Implementation features:
1, the string according to 16 decimal number, self-increment, only with the modification
int hex = Str.toint (&ok, 10);
hex=hex+1;
2, the string in accordance with the 10 binary number, self-increment
int hex = Str.toint (&ok, 16);
hex=hex+1;
3. Convert the string to 16, and then display it as a 10 binary number.
int hex = Str.toint (&ok, 16);
QString t = qstring::number (hex, ten). ToUpper ();
4. Convert the string to 10 decimal and then display it in 16 digits
int hex = Str.toint (&ok, 10);
QString t = qstring::number (hex, +). ToUpper ();
Principle:
int Qstring::toint (BOOL * OK = 0, int base = ten) const
Returns the string converted (convert) to a int using base base, which is ten by default and must be between 2 and 36 (conversion binary, only 2 To 36, binary, 10 binary, 9 binary, etc. can be converted), or 0. Returns 0 if the conversion fails.
If A conversion error occurs, *ok is set to false; Otherwise *ok is set to true.
The conversion succeeds, the return value is OK is 1, return error, the value is 1. You can also use the OK value to determine whether the conversion was successful.
If base is 0, the C language Convention are used:if the string begins with "0x" and base is used; If the string begin S with "0", base 8 is used; Otherwise, base is used.
The string conversion would always be happen in the ' C ' locale. For locale dependent conversion use Qlocale::toint ()
Yearline->settext (Qstring::number (cmd.trimmed () ToInt (), 10)