From kde-devel Wed Aug 20 12:14:55 2003 From: Nicolas Goutte Date: Wed, 20 Aug 2003 12:14:55 +0000 To: kde-devel Subject: Re: QString data X-MARC-Message: https://marc.info/?l=kde-devel&m=106138188510830 Just a question: are you sure that you cannot use QCString? QCString would be indendant of UCS-2 or UCS-4, so you would not get this problem. (Of course the QCString would be probably in UTF-8 in this case.) However, it does not avoid the deep copy of your data. So personally, as you are already calling C functions for the mapping, I would go further and do the reading also with normal null-terminated C strings. Then you can compare with a QCString with Qt's portable functions like qstrcmp. (Of course, if your file cannot have null-terminated strings for a reason or another, my idea is not good.) Have a nice day! On Wednesday 20 August 2003 13:54, Johnny Andersson wrote: > On Wednesday 20 August 2003 13.25, Tim Jansen wrote: > > You can cast your string to const QChar* and use it as argument of > > QConstString ( const QChar * unicode, uint length ), provided that: > > - you are sure that all characters in your utf16 string have only 16 bits > > (you may need to check that) > > - you did not compile Qt with QT_QSTRING_UCS_4. In other words, QChar has > > 2 bytes and not 4. You can check that at compile time, a sizeof(QChar) > > should be enough > > Thanks for the replies (Tim and Harri). I'd really appreciate it if you > could clear up a few points for me: > > I'm creating a program that converts a list of QStrings to a file that can > be mmap()ed into memory (for later use on a handheld device). It's a > dictionary application. What I want to do is to write strings to a file > (using my Qt program), then mmap() the file and access the strings without > copying them to RAM. What I'm doing now is: > > Write strings to file. I'm iteration through the strings, using > QDataStream.writeRawBytes(string[i], sizeof(QChar)). > > Then I mmap() the file into the process, and I have a list of offsets to > each string within the file. I create QConstString objects under the > assumption that each character is sizeof(QChar). > > Would you say that's a good way to do it, or am I just lucky if it works? > ;) > > >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to > >> unsubscribe << >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<