I'm trying to open a file to my texteditor and I want to change and save it but it gives me that error
QFSFileEngine::open: No file name specified
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QFileDialog>
#include <QFile>
#include <QFileInfo>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_triggered()
{
if(!file.isEmpty())
{
nFile.setFileName (file);
{
nFile.fileName ()=file;
nFile.close();
ui->textEdit->setPlainText (text);
}
}
}
void MainWindow::on_actionSave_triggered() //this is save function
{
//QString file; //I tried to fix the problem with these parts
//nFile.setFileName (file);
{
out << ui->textEdit->toPlainText ();
nFile.flush();
nFile.close();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QFileDialog>
#include <QFile>
#include <QFileInfo>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_triggered()
{
QString file = QFileDialog::getOpenFileName(this); //this is open function
if(!file.isEmpty())
{
nFile.setFileName (file);
if(nFile.open (QFile::ReadOnly | QFile::Text))
{
nFile.fileName ()=file;
QTextStream in(&nFile);
QString text = in.readAll ();
nFile.close();
ui->textEdit->setPlainText (text);
}
}
}
void MainWindow::on_actionSave_triggered() //this is save function
{
//QString file; //I tried to fix the problem with these parts
//nFile.setFileName (file);
if(nFile.open (QFile::WriteOnly | QFile::Text))
{
QTextStream out(&nFile);
out << ui->textEdit->toPlainText ();
nFile.flush();
nFile.close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks