diff --git a/readfile/2.png b/readfile/2.png new file mode 100644 index 0000000..569a5de Binary files /dev/null and b/readfile/2.png differ diff --git a/readfile/main.cpp b/readfile/main.cpp new file mode 100644 index 0000000..c6f465d --- /dev/null +++ b/readfile/main.cpp @@ -0,0 +1,49 @@ +#include "widget.h" +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + quint32 value; + QImage image("C:/Users/fzyz_sb/Desktop/readfile/2.png"), outImage; + QMap map, outMap; + map["red"] = "RED"; + map["green"] = "GREEN"; + map["blue"] = "BLUE"; + + QFile file("facts.dat"); + if (!file.open(QIODevice::WriteOnly)) { + cerr << "cannot open file for writing:" + << qPrintable(file.errorString()) << endl; + return 1; + } + //写入二进制文件 + QDataStream out(&file); + out.setVersion(QDataStream::Qt_5_3); + out << quint32(0x12345678) << image << map; + file.close(); + + QFile outFile("facts.dat"); + if (!outFile.open(QIODevice::ReadOnly)) { + cerr << "cannot open file for reading:" + << qPrintable(outFile.errorString()) << endl; + return 1; + } + //读取二进制文件 + QDataStream in(&outFile); + in.setVersion(QDataStream::Qt_5_3); + in >> value >> outImage >> outMap; + + qDebug() << "value is:" << value; + qDebug() << outMap["blue"] << " " << outMap["red"] << " " << outMap["green"] << endl; + + return a.exec(); +} diff --git a/readfile/readfile.pro b/readfile/readfile.pro new file mode 100644 index 0000000..879e7be --- /dev/null +++ b/readfile/readfile.pro @@ -0,0 +1,20 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-11-18T20:11:14 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = readfile +TEMPLATE = app + + +SOURCES += main.cpp\ + widget.cpp + +HEADERS += widget.h + +FORMS += widget.ui diff --git a/readfile/readfile.pro.user b/readfile/readfile.pro.user new file mode 100644 index 0000000..6dd55f1 --- /dev/null +++ b/readfile/readfile.pro.user @@ -0,0 +1,255 @@ + + + + + + EnvironmentId + {a8c18b7e-8020-49b9-a0ef-0165c784344f} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.3 MinGW 32bit + Desktop Qt 5.3 MinGW 32bit + qt.53.win32_mingw482_kit + 0 + 0 + 0 + + C:/Users/fzyz_sb/Desktop/build-readfile-Desktop_Qt_5_3_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/fzyz_sb/Desktop/build-readfile-Desktop_Qt_5_3_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + 构建 + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + 清理 + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + 在本地部署 + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + readfile + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/fzyz_sb/Desktop/readfile/readfile.pro + + readfile.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 16 + + + Version + 16 + + diff --git a/readfile/widget.cpp b/readfile/widget.cpp new file mode 100644 index 0000000..de81017 --- /dev/null +++ b/readfile/widget.cpp @@ -0,0 +1,14 @@ +#include "widget.h" +#include "ui_widget.h" + +Widget::Widget(QWidget *parent) : + QWidget(parent), + ui(new Ui::Widget) +{ + ui->setupUi(this); +} + +Widget::~Widget() +{ + delete ui; +} diff --git a/readfile/widget.h b/readfile/widget.h new file mode 100644 index 0000000..896177c --- /dev/null +++ b/readfile/widget.h @@ -0,0 +1,22 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include + +namespace Ui { +class Widget; +} + +class Widget : public QWidget +{ + Q_OBJECT + +public: + explicit Widget(QWidget *parent = 0); + ~Widget(); + +private: + Ui::Widget *ui; +}; + +#endif // WIDGET_H diff --git a/readfile/widget.ui b/readfile/widget.ui new file mode 100644 index 0000000..8541684 --- /dev/null +++ b/readfile/widget.ui @@ -0,0 +1,20 @@ + + Widget + + + + 0 + 0 + 400 + 300 + + + + Widget + + + + + + +