[Qt-interest] How to compress QString
Iurii Gordiienko
hordi at ukr.net
Thu Apr 16 13:48:14 CEST 2009
We can't convert UNICODE string to UTF-8 because data will be loss. QByteArray compress(const QString& s)
{
return qCompress( QByteArray(reinterpret_cast<const char*>(s.utf16()),s.size()*sizeof(ushort)), 9);
}
QString uncompress(const QByteArray& ba)
{
QString ret;
if(!ba.isEmpty()){
QByteArray v = qUncompress(ba);
if(!v.isEmpty() && !(v.size() % sizeof(ushort)) ){
ret.setUtf16( reinterpret_cast<const ushort*>(v.constData()), v.size() / sizeof(ushort) );
}
}
return ret;
}
--- Original Message ---
From: Jan Kundr?t <jkt at gentoo.org>
To: qt-interest at trolltech.com
Date: 16 april, 14:35:00
Subject: Re: [Qt-interest] How to compress QString
Ankit Agarwal wrote:
> Whats the advantage that we get by converting the string to UTF - 8?
No need to figure out magic multiplication constants for figuring out
the string size. Basically, if you convert a QString to a QByteArray
holding its UTF-8 representation, you can tell the size of the data from
QByteArray's size(). Also having a stable and well-documented
intermediate format (which a byte array of UTF-8 data is) always helps.
Cheers
-jkt
--
cd /local/pub && more beer > /dev/mouth
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
--
Рецепт успеха в Сети. Новый номер журнала InternetUA.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090416/6d0b2a08/attachment.html
More information about the Qt-interest-old
mailing list