Conversion between char * and const char * of various data types char * character = "hello11"; const char * CH2 = "hello22"; CH2 = character; // No error is reported, but there is a warning character = (char *) CH2;
There are many methods to convert Char to qstring. I use: Char A = 'B'; qstring STR; STR = qstring ();
The conversion of qstring to Char method also uses qstring STR = "ABC"; char * Ch; CH = Str. tolatin1.data ();
Convert qbytearray to char * Ch; // do not define it as CH [N]; qbytearray byte; CH = byte. Data ();
Char * To qbytearray char * Ch; qbytearray byte; byte = qbytearray (CH );
Convert qstring to qbytearray byte; qstring string; byte = string. toascii ();
Convert qbytearray to qstring qbytearray byte; qstring string; string = qstring (byte). Here we will summarize the types of output: qdebug () <"print "; qdebug () <tr ("print"); qdebug () <ch; (CH is char type) qdebug () <tr (CH); qdebug () <bytearray; (bytearray is qbytearray type) qdebug () <tr (bytearray); qdebug () <STR; (STR is qstring type) But qdebug () <tr (STR); No. To use the tr () function to output qstring characters, the following must be performed: qdebug () <tr (Str. tolatin1 );
Convert int to qstring int A = 10; qstring B; B = qstring: Number ()
Convert qstring to int qstring A = "120" int B; B = A. toint ()
Bytes --------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Qdatastream reads and writes data
1 QFilefile("c:/a");
2
3 file.open(QIODevice::ReadOnly);
4
5 QDataStream out(&file);//readthedataserializedfromthefile
6
7 QByteArraybarr;
8
9 QFilefile2("c:/b");
10
11 file2.open(QIODevice::WriteOnly);
12
13 int maxSize=1024;
14
15 char* datas=new char [maxSize];
16
17 while(!out.atEnd())
18
19 {
20
21 int actuallyRead=out.readRawData(datas,maxSize);
22
23 barr.append(datas,actuallyRead);//QMessageBox::information(this,"","a","");
24
25 }
26
27 delete[]datas;QMessageBox::information(this,"",QString(barr),"");
28
29 file2.write(barr);
30
31 file.close();
32
33 file2.close();