Created
February 26, 2015 20:17
-
-
Save ThereExistsX/cc44597d05e5e42c0b3d to your computer and use it in GitHub Desktop.
File IO
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
#include "fileio.h" | |
#include <QFile> | |
#include <QTextStream> | |
FileIO::FileIO() | |
{ | |
} | |
void FileIO::save(QString text){ | |
QFile file("text.txt"); | |
if(file.open(QIODevice::ReadWrite)){ | |
QTextStream stream(&file); | |
stream << text << endl; | |
} | |
return; | |
} | |
FileIO::~FileIO() | |
{ | |
} | |
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
#include <QObject> | |
#ifndef FILEIO_H | |
#define FILEIO_H | |
class FileIO : public QObject | |
{ | |
Q_OBJECT | |
public: | |
FileIO(); | |
Q_INVOKABLE void save(QString text); | |
~FileIO(); | |
}; | |
#endif // FILEIO_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
#include <QApplication> | |
#include <QQmlApplicationEngine> | |
#include <QQmlContext> | |
#include "fileio.h" | |
int main(int argc, char *argv[]) | |
{ | |
QApplication app(argc, argv); | |
QQmlApplicationEngine engine; | |
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); | |
engine.rootContext()->setContextProperty("FileIO", new FileIO()); | |
return app.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
import QtQuick 2.4 | |
import QtQuick.Controls 1.3 | |
import QtQuick.Window 2.2 | |
import QtQuick.Dialogs 1.2 | |
ApplicationWindow { | |
title: qsTr("Hello World") | |
width: 640 | |
height: 480 | |
visible: true | |
TextArea { | |
id: saveMe | |
x: 200 | |
y: 84 | |
} | |
Button { | |
id: button1 | |
x: 283 | |
y: 266 | |
text: qsTr("Save") | |
onClicked: FileIO.save(saveMe.text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment