forked from leichaojian/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c149505
commit c6e6555
Showing
7 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |