Do you understand what QDataStream does?
problem is here.Yes i try understand QDataStream.but you see i cant this.Whats my problem ?
wysota was asking this because there is a discrepancy between what you write about your goals and how QDataStream works.
In the text of your posting you write that you want to do arbitrary binary I/O, which QDataStream is not intended for.
So in order to help you further we will need to know which of the two things you actually want.
Cheers,
_
im working huffman encoding.I have QMap and QString(character code) and i must writing them binary file but icant this.Whats way this?
Huffman coding for compression typically requires direct access to bytes, manipulating bits within them, and building a frequency weighted tree. What a QMap or QString have to do with that I have no idea.
You read bytes from a QFile (QIODevice) with QIODevice::read(), and write them with QIODevice::write().
Edit: In case there is any doubt, a QChar is not a byte
example from my project;
This is my freq and huff code table.I have all i needs.Now i have QMap.frequency____character____huffman code(bit)
-------------------------------------------------------------
50_____________a______________0
35_____________b______________10
20_____________k______________110
10_____________m_____________ 1110
8______________d______________11111
4______________g______________11110
Now for example my text is "aabkdgmma" so this codes(look table) are "0 0 10 110 11111 11110 1110 1110 0"->Qt Code:
QMap<char,int>mymap; //char -----> character from table //int -----> frequency from the table //so QMap keeping character and frequency i mean QMap my table.To copy to clipboard, switch view to plain text mode
--->"00101101111111110111011100"
I want to do saving mymap and codes to file and earning size.I hope to explain my problem.How can i my bits to byte and mymap write to binary file.Qt Code:
QString codes; //codes="00101101111111110111011100" (they are bits).To copy to clipboard, switch view to plain text mode
Thanks for all helping and your patience.
Have a look at QByteArray and QFile::write(). That's all you need.
seniorc (17th December 2013)
Since you decided to work with strings rather than bits you need to convert your code string into a packed set of bytes containing those bits. You need to determine how to deal with the incomplete byte you are likely to have at the end (perhaps pad with zeroes and record the number of padding bits as the first three bits of the output). The order of bit packing in bytes is important if your code is not the decoder. Then write the resulting bytes to file with QIODevice::write().
A compact way to represent the dictionary is more complex, and you should try to walk before you run.
http://www.siggraph.org/education/ma..._tutorial.html
seniorc (17th December 2013)
Bookmarks