PDA

View Full Version : save contents QTextEdit in a .txt file



giorgik
31st May 2012, 09:44
I found an example of this type:


QString nomeFile = QFileDialog::getSaveFileName(this, tr("Salva il File"), "",
tr("File di Testo (*.txt);;C++ File (*.cpp *.h)"));
if (nomeFile != "") {
QFile file(nomeFile);

if (file.open(QIODevice::ReadWrite)) {
---> QTextStream stream(&file); <-----
stream << ui->editaTesto->toPlainText();
file.flush();
file.close();
}
else {
QMessageBox::critical(this, tr("Errore"), tr("Non posso salvare il file"));
return;
}
}

When I compile I get this error message referring to the line of code with the arrows:


C:\Qt\progetti\test-MainWindow\notepad.cpp:46: error: variable 'QTextStream stream' has initializer but incomplete type

How should I write?

Thanks to all

wysota
31st May 2012, 09:59
You forgot:


#include <QTextStream>

giorgik
31st May 2012, 10:11
Thank you very much