Skip to content

Commit

Permalink
add readfile
Browse files Browse the repository at this point in the history
  • Loading branch information
leichaojian committed Nov 18, 2014
1 parent c149505 commit c6e6555
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 0 deletions.
Binary file added readfile/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions readfile/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "widget.h"
#include <QApplication>
#include <QImage>
#include <QMap>
#include <QFile>
#include <iostream>
#include <QDebug>
#include <string>
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<QString, QString> 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();
}
20 changes: 20 additions & 0 deletions readfile/readfile.pro
Original file line number Diff line number Diff line change
@@ -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
255 changes: 255 additions & 0 deletions readfile/readfile.pro.user

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions readfile/widget.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions readfile/widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
Q_OBJECT

public:
explicit Widget(QWidget *parent = 0);
~Widget();

private:
Ui::Widget *ui;
};

#endif // WIDGET_H
20 changes: 20 additions & 0 deletions readfile/widget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ui version="4.0">
<class>Widget</class>
<widget class="QWidget" name="Widget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Widget</string>
</property>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>

0 comments on commit c6e6555

Please sign in to comment.