Qt 中所有IO 设备的基类是QIODevice,派生出来的子类有以下几种
1.QFile:磁盘文件,存储在磁盘中的文件
2.QBuffer :内存文件,存储在内存中
3.QTcpSocket
4.QUdpSocket
//io method
1.QTextStream
2.QDataStream
#if 0
QFile file("C:\\Users\\michael\\Desktop\\1.txt");
file.open(QIODevice::ReadWrite);
file.write(QByteArray("yzh"));
file.write(QByteArray("yzh"));
file.close();
QByteArray ba("中国人");
QString str("是什么意思");
qDebug()<<ba.size()<<endl<<str.size()<<endl;
#endif
#if 0
QBuffer buf;
buf.open(QIODevice::ReadWrite);
buf.write("0901");
buf.close();
qDebug()<<buf.buffer();
#endif
//内存文件应用
#if 1
//send side
QBuffer buf;
buf.open(QIODevice::ReadWrite);
QPixmap pix("C:\\Users\\michael\\Desktop\\green.png");
// pix.save("C:\\Users\\michael\\Desktop\\greenball.png");//以文件名方式另存为
pix.save(&buf,"PNG");//图片保存在内存文件中,效率更高,可使用网络进行传输.
qDebug()<<buf.buffer().size();
// recv side
QPixmap recvPix;
recvPix.loadFromData(buf.buffer(), "PNG");
QLabel* label = new QLabel(this);
label->setPixmap(recvPix);
#endif
//QTextStream 调试用,解析时候比较麻烦,数据类型太杂
#if 0
QFile file("../textstream.txt");
file.open(QIODevice::ReadWrite);
QTextStream textStream(&file);
textStream << 1 << "abc" << 1.2 << QString("abc");
file.close();
#endif
//方便读写,文件解析
#if 1
QFile file("../datastream.txt");
file.open(QIODevice::ReadWrite);
QDataStream wDataStream(&file);
wDataStream <<1<< "abc" << 1.2 << QString("abc") << QPoint(1, 1);
int i;
char* buffer;
double d;
QString str;
QPoint pt;
QFile rFile("../datastream.txt");
rFile.open(QIODevice::ReadWrite);
QDataStream rDataStream(&rFile);
rDataStream >> i >> buffer >> d >> str >> pt;
qDebug() << i << buffer << d << str << pt;
delete []buffer;
file.close();
#endif
this->setFixedSize(200,200);