Answer the question
In order to leave comments, you need to log in
How to write to a file (QT)?
QFile file2;
file2.setFileName(QString("r.txt"));
if(file2.open(QIODevice::ReadWrite)) qDebug("Op");
if(file2.exists()) qDebug("Ex");
if(file2.write("ya")) qDebug("ololo");
file2.close();
#include <QMainWindow>
#include <QtDeclarative/QDeclarativeView>
#include <QGraphicsObject>
#include <QtGui>
#include <QDeclarativeContext>
#include <QDeclarativeEngine>
#include <QSystemTrayIcon>
#include <QTime>
#include <QFile>
#include <QTextStream>
#include <QTimer>
Answer the question
In order to leave comments, you need to log in
void ScriptWidget::onSaveButtonClick()
{
QFile updateScriptFile("update-script");
if (!updateScriptFile.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::critical(this, tr("I/O Error"), tr("Error opening file %1\n"
"Error: %2")
.arg(updateScriptFile.fileName())
.arg(updateScriptFile.errorString()));
return;
}
QTextStream out(&updateScriptFile);
out << ui->textEdit->toPlainText(); // Get text from the QTextEdit Widget
updateScriptFile.close();
emit signalSendMessageToStatusBar(QString(tr("File Saved.")));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question