QFlie | 访问本地文件系统或者嵌入资源 |
QTemporaryFile | 创建和访问本地文件系统的临时文件 |
QBuffer | 读写 QByteArray |
QProcess | 运行外部程序,处理进程间通讯 |
QTcpSocket | TCP 协议网络数据传输 |
QUdpSocket | 传输 UDP 报文 |
QSslSocket | 使用 SSL/TLS 传输数据 |
- QImageimage( "philip.png" );
- QMap<QString,QColor>map;
- map.insert( "red" ,Qt::red);
- map.insert( "green" ,Qt::green);
- map.insert( "blue" ,Qt::blue);
- QFilefile( "facts.dat" );
- if (!file.open(QIODevice::WriteOnly)){
- std::cerr<< "Cannotopenfileforwriting:"
- <<qPrintable(file.errorString())<<std::endl;
- return ;
- }
- QDataStreamout(&file);
- out.setVersion(QDataStream::Qt_4_3);
- out<<quint32(0x12345678)<<image<<map;
- quint32n;
- QImageimage;
- QMap<QString,QColor>map;
- QFilefile( "facts.dat" );
- if (!file.open(QIODevice::ReadOnly)){
- std::cerr<< "Cannotopenfileforreading:"
- <<qPrintable(file.errorString())<<std::endl;
- return ;
- }
- QDataStreamin(&file);
- in.setVersion(QDataStream::Qt_4_3);
- in>>n>>image>>map;
- QFilefile( "file.xxx" );
- file.open(QIODevice::WriteOnly);
- QDataStreamout(&file);
- //Writeaheaderwitha"magicnumber"andaversion
- out<<(quint32)0xA0B0C0D0;
- out<<(qint32)123;
- out.setVersion(QDataStream::Qt_4_0);
- //Writethedata
- out<<lots_of_interesting_data;
- QFilefile( "file.xxx" );
- file.open(QIODevice::ReadOnly);
- QDataStreamin(&file);
- //Readandchecktheheader
- quint32magic;
- in>>magic;
- if (magic!=0xA0B0C0D0)
- return XXX_BAD_FILE_FORMAT;
- //Readtheversion
- qint32version;
- in>>version;
- if (version<100)
- return XXX_BAD_FILE_TOO_OLD;
- if (version>123)
- return XXX_BAD_FILE_TOO_NEW;
- if (version<=110)
- in.setVersion(QDataStream::Qt_3_2);
- else
- in.setVersion(QDataStream::Qt_4_0);
- //Readthedata
- in>>lots_of_interesting_data;
- if (version>=120)
- in>>data_new_in_XXX_version_1_2;
- in>>other_interesting_data;
本文出自 “豆子空间 ” 博客,请务必保留此出处http://devbean.blog.51cto.com/448512/293892