Conversion between qstring, Char, Int, and qbytearray in QT

Source: Internet
Author: User

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();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.