Problem to save text edit content to a file
-
I created a QFileDialog to get the user to save the content of a QTextEdit and everything works fine, I'm able to save the document however when I open it with a text editor, there is not the text from the text edit but only hexadecimals and I don't get how I could fix it, here is my code, and codeReH is a QString which contains the text from my QTextEdit :
void FenCodeGenere::ouvrirSaveH() {
QString nomFileH = QFileDialog::getSaveFileName(this, tr("Sauvegarder le fichier"), "", tr("Header C++ (*.h)")); if (nomFileH != "") { QFile fileH(nomFileH); if (fileH.open(QFile::WriteOnly)) { QTextStream stream(&fileH); stream << codeReH; } else { QMessageBox::critical(this, tr("Erreur"), tr("Impossible de sauvegarder le fichier")); } }
Thank you in adavance !
} -
I created a QFileDialog to get the user to save the content of a QTextEdit and everything works fine, I'm able to save the document however when I open it with a text editor, there is not the text from the text edit but only hexadecimals and I don't get how I could fix it, here is my code, and codeReH is a QString which contains the text from my QTextEdit :
void FenCodeGenere::ouvrirSaveH() {
QString nomFileH = QFileDialog::getSaveFileName(this, tr("Sauvegarder le fichier"), "", tr("Header C++ (*.h)")); if (nomFileH != "") { QFile fileH(nomFileH); if (fileH.open(QFile::WriteOnly)) { QTextStream stream(&fileH); stream << codeReH; } else { QMessageBox::critical(this, tr("Erreur"), tr("Impossible de sauvegarder le fichier")); } }
Thank you in adavance !
}@arthurguedon
Hi,friend, welcome devnet.- What is store in
codeReH
? str ? or other some? can you debug it before save it? QFile
open , you can try use theQIODevice::Text
like the below.
QFile file("out.txt"); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return;
- What is store in
-
Thanks for your answer, codeReH stores the text from my QTexEdit, when I debug I don't see any problem as codeReH contains what was written in the text edit.
I tried using the QIODevice::Text but it didn't change anything. -
hi
i would try
stream << "TEST TEST";and see.