From c6e6555661f5355f35a630e8776608dae50b54e9 Mon Sep 17 00:00:00 2001 From: leichaojian Date: Tue, 18 Nov 2014 22:52:46 +0800 Subject: [PATCH] add readfile --- readfile/2.png | Bin 0 -> 2576 bytes readfile/main.cpp | 49 +++++++ readfile/readfile.pro | 20 +++ readfile/readfile.pro.user | 255 +++++++++++++++++++++++++++++++++++++ readfile/widget.cpp | 14 ++ readfile/widget.h | 22 ++++ readfile/widget.ui | 20 +++ 7 files changed, 380 insertions(+) create mode 100644 readfile/2.png create mode 100644 readfile/main.cpp create mode 100644 readfile/readfile.pro create mode 100644 readfile/readfile.pro.user create mode 100644 readfile/widget.cpp create mode 100644 readfile/widget.h create mode 100644 readfile/widget.ui diff --git a/readfile/2.png b/readfile/2.png new file mode 100644 index 0000000000000000000000000000000000000000..569a5dee7feca7c1e1460d819500917210ae8d11 GIT binary patch literal 2576 zcma)8cT|(v68}Px9*Q6c2?9oW3IRkQCW=ggclcjnIT-no-tfiV=~m*ximK*$KK zZ^hU#NT2-?ew9@WO@@J4d1-L}I}NNba4$OU~Trg={cw`%wFf| zmvFQ~#($|e+;z{mMN1afp2h-lMl%kZ*&Qk!++71}PjPNnx14EFbC$lWipNK8iSsv@ zgiD9rsNu!HZ;6mcabS6Ot4~Iu7qb$6?`V#tE7n*Zw}fjkA1>LeeWwv4^#r26)}fsb zS0ecqiYRD@R#L=13x3bl=(I^dRRJb2d~mCL$rC2V4K!UpO0CcWVR;AyCti&ZOwlbSe;4!26x+&-V&2xY6CUmbHFor=uq#vQ_ zQ}@8z0UUm}%L*PQ1z1T?`-TNVvLmc`01@97_tFd5?1~+IB0*i2{7+gY!J;e$&PfSt2=uGNFw_Bg{$Fu$M!GJ-8A>mjXv=l|8HuCCv zIM5wJIHqa7W;ndV2h(X9N^0$k{D>y?-aB0lsbkfYg$Gnw4yoXo^@igaXH`kA^L!ay zYm86Wtm64Jv-p0Nn@ib|R!~Q}*`?iagUShqzK&Q)kDyVOUyRxU+E37O^;va&>;`J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Mz-XJrtoSz)#}7aLnSz?bfNP>c}wx(n#t_o%nCy_9VI!1rm|y_UnV+j z?zOSwn2|VgyLb5y!`pohk4A@Qg4upC*{A>f6#kN<|681oD6TAbpAXrbWH)qxkpV`( JT=#bLKLNMc;*$UX literal 0 HcmV?d00001 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 + + + + + + +