Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved Problem to save text edit content to a file

    General and Desktop
    3
    4
    1022
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      arthurguedon last edited by arthurguedon

      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 !
      }

      joeQ 1 Reply Last reply Reply Quote 0
      • joeQ
        joeQ @arthurguedon last edited by

        @arthurguedon
        Hi,friend, welcome devnet.

        1. What is store in codeReH? str ? or other some? can you debug it before save it?
        2. QFile open , you can try use the QIODevice::Text like the below.
         QFile file("out.txt");
         if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                  return;
        

        Just do it!

        1 Reply Last reply Reply Quote 0
        • A
          arthurguedon last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            hi
            i would try
            stream << "TEST TEST";

            and see.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post