1 #include "mainwindow.h" 2 #include <QApplication> 3 #include <QFile> 4 #include <QDebug> 5 6 int main(int argc, char *argv[]) 7 { 8 QApplication a(argc, argv); 9 10 QFile file("1.bin"); 11 file.open(QIODevice::WriteOnly|QIODevice::Truncate); 12 QDataStream out(&file); 13 QString str1 = "hello"; 14 QChar ch1 = 'A'; 15 out << str1<<1234<<ch1; 16 file.close(); 17 18 file.setFileName("1.bin"); 19 if(file.open(QFile::ReadOnly)) 20 { 21 QDataStream in(&file); 22 QString str; 23 int data; 24 QChar ch; 25 in>>str>>data>>ch; 26 qDebug() << str << data << ch; 27 } 28 29 MainWindow w; 30 w.show(); 31 32 return a.exec(); 33 }