Hello,
I would like to create a new empty text file. The user should type in a name of the file and perhaps write in some text then press save to create a file at a given place.
I can write and read from a file. But I need some help with creating new files. I have tried to work with QTextDocumentWriter and QTextDocumentFragment, and it's not going so well.. I also wonder about setDevice, what should I set it to?
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
void MainWindow::on_pushButton_clicked() {
QString fileName = ui->lineEdit->text();
QFile fil("C:/Users/" + fileName + ".txt");
QString writtenToFile = ui->textEdit->toPlainText();
QTextDocumentWriter writer(&fil, "plaintext");
writer.setFormat("txt");
writer.setFileName(fileName);
// writer.setDevice?
writer.write(QTextDocumentFragment::fromPlainText(writtenToFile));
}
|
I am very happy for all of your help.
//Jennifer