各种数据类型的相互转换 char * 与 const char *的转换 char *ch1="hello11"; const char *ch2="hello22"; ch2 = ch1;//不报错,但有警告 ch1 = (char *)ch2;
char 转换为 QString 其实方法有很多中,我用的是: char a='b'; QString str; str=QString(a);
QString 转换为 char 方法也用很多中 QString str="abc"; char *ch; ch = str.toLatin1.data();
QByteArray 转换为 char * char *ch;//不要定义成ch[n]; QByteArray byte; ch = byte.data();
char * 转换为 QByteArray char *ch; QByteArray byte; byte = QByteArray(ch);
QString 转换为 QByteArray QByteArray byte; QString string; byte = string.toAscii();
QByteArray 转换为 QString QByteArray byte; QString string; string = QString(byte); 这里再对这俩中类型的输出总结一下: qDebug()<<"print"; qDebug()<
|
int 转 QString int a=10; QString b; b=QString::number(a)
QString 转int QString a="120" int b; b=a.toInt()
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
QDataStream读写数据
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();
摘自 风行雪舞
阅读(614) | 评论(0) | 转发(0) |