Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Size Reserve in Type Conversion
Forum Updated to NodeBB v4.3 + New Features

Size Reserve in Type Conversion

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 6 Posters 602 Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    Zeyad Khaled
    wrote on last edited by
    #1

    iam trying to compress Xml File Using huffman Compression the code is Working and the out put is (0's,1's ) , and the Method Should Make the File Size less than the original One I think i have done something wrong in type Conversions Here i followed Some Codes i found on google , Thx in advance

     QString file_name=QFileDialog::getSaveFileName(this,"Select a file","C://",tr("All files (*.*);;Huffman Files (*.huff)"));
        QSaveFile file(file_name);
        file.open(QIODevice::WriteOnly);
        QString text =ui->plainTextEdit->toPlainText();
        string x=text.toStdString();
        string Result=Huffman_encoding(x);
        QByteArray y=QByteArray::fromStdString(Result);
        file.write(y);
        file.commit();
    
    Pl45m4P jsulmJ 2 Replies Last reply
    0
    • Z Zeyad Khaled

      iam trying to compress Xml File Using huffman Compression the code is Working and the out put is (0's,1's ) , and the Method Should Make the File Size less than the original One I think i have done something wrong in type Conversions Here i followed Some Codes i found on google , Thx in advance

       QString file_name=QFileDialog::getSaveFileName(this,"Select a file","C://",tr("All files (*.*);;Huffman Files (*.huff)"));
          QSaveFile file(file_name);
          file.open(QIODevice::WriteOnly);
          QString text =ui->plainTextEdit->toPlainText();
          string x=text.toStdString();
          string Result=Huffman_encoding(x);
          QByteArray y=QByteArray::fromStdString(Result);
          file.write(y);
          file.commit();
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Zeyad-Khaled

      Where is it related to Qt? What is your question?

      Probably nobody will fix code you copied from elsewhere and which is not working.

      Btw: The code you've posted doesnt look too wrong.
      You should check the huffman_encoding function or debug to see what happens exactly.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      Z 1 Reply Last reply
      0
      • Z Zeyad Khaled

        iam trying to compress Xml File Using huffman Compression the code is Working and the out put is (0's,1's ) , and the Method Should Make the File Size less than the original One I think i have done something wrong in type Conversions Here i followed Some Codes i found on google , Thx in advance

         QString file_name=QFileDialog::getSaveFileName(this,"Select a file","C://",tr("All files (*.*);;Huffman Files (*.huff)"));
            QSaveFile file(file_name);
            file.open(QIODevice::WriteOnly);
            QString text =ui->plainTextEdit->toPlainText();
            string x=text.toStdString();
            string Result=Huffman_encoding(x);
            QByteArray y=QByteArray::fromStdString(Result);
            file.write(y);
            file.commit();
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Zeyad-Khaled Why don't you use https://doc.qt.io/qt-5/qbytearray.html#qCompress ?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          The implied problem is, I guess, "the Method Should Make the File Size less than the original One," and it is not.

          Naive Huffman coding can produce outputs slightly larger than the input for certain quite unlikely inputs: XML input is going to be compressible. However, if you actually output the characters '0' and '1' rather than bytes packed with 0/1 bits, or some diagnostic info about the Huffman tree, then the output will certainly be bigger or unexpected.

          No way for us to tell without the implementation details of "Some Codes i found on google."

          1 Reply Last reply
          1
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            And one more comment - are you sure encode() returns a std::string and not an array of bytes? What does this function do? When it compress data then std::string is for sure wrong.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • Pl45m4P Pl45m4

              @Zeyad-Khaled

              Where is it related to Qt? What is your question?

              Probably nobody will fix code you copied from elsewhere and which is not working.

              Btw: The code you've posted doesnt look too wrong.
              You should check the huffman_encoding function or debug to see what happens exactly.

              Z Offline
              Z Offline
              Zeyad Khaled
              wrote on last edited by
              #6

              @Pl45m4 The Huffman Function Returns string in 0's and 1's , i want it to be saved as it is not as string (every 0,1 saved in one bit) i thought there will be some type conversion in Qt to be able to do this

              JonBJ C 2 Replies Last reply
              0
              • Z Zeyad Khaled

                @Pl45m4 The Huffman Function Returns string in 0's and 1's , i want it to be saved as it is not as string (every 0,1 saved in one bit) i thought there will be some type conversion in Qt to be able to do this

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Zeyad-Khaled
                That's not a job/facility provided in Qt. If you have strings of digits and you want to convert to bits and pack, that's just straight C++ to write.

                1 Reply Last reply
                0
                • Z Zeyad Khaled

                  @Pl45m4 The Huffman Function Returns string in 0's and 1's , i want it to be saved as it is not as string (every 0,1 saved in one bit) i thought there will be some type conversion in Qt to be able to do this

                  C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #8

                  @Zeyad-Khaled said in Size Reserve in Type Conversion:

                  The Huffman Function Returns string in 0's and 1's

                  If this routine returns a string of '0' and '1' characters, e.g. "01011101...", then your best course of action would be to write, find, or adapt an implementation that returns a bunch of bytes (QByteArray). In the case of the example the first byte in the array should be 0x5D.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved