Buffered QTextStream + pos() == ?
[Disclaimer: Qt 4.2 is not released yet, and anything can still change.]
QTextStream in Qt 3 was unbuffered. Feeding bytes by bytes into a codec which appended QChar by QChar into a QString, it did have room for some speed improvements. So in Qt 4.0, we introduced QTextStream's replacement: ... QTextStream! That is - we completely refactored its insides, but kept the API more or less the same. The new QTextStream is buffered. That gave QTextStream in Qt 4 a 16x performance boost over Qt 3. For most operations, it's just about 1.5x slower than raw QFile access. Which is very very good.
The downside from this change was that the stream's device position, which can be retrieved by accessing QTextStream::device()->pos(), became unreliable. Because QTextStream buffers its input, it reads ahead a chunk of bytes. In Qt 3, QTextStream was always in sync with the device position. In Qt 4, the device is way ahead! And this upset some people who ported from Qt 3 to Qt 4, who used seek() and pos() together to navigate text files.
Thiago Macieira and I found a beautiful solution to this problem, and I just submitted QTextStream::pos() into what will become Qt 4.2. Together with QTextStream::seek(), which does what QTextStream::device()->seek() did in Qt 3, you can do exactly what you could in Qt 3, but it's just faster than before.
In addition, Qt 3's textstream class has been ported into Qt3Support, so you'll see a Q3TextStream class which will make porting even easier.
Subscribe to our newsletter
Try Qt 6.3 Now!
Download the latest release here: www.qt.io/download.
Qt 6 was created to be the productivity platform for the future, with next-gen 2D & 3D UX and limitless scalability.
Explore Qt World
Check our Qt demos and case studies in the virtual Qt World
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don't want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu