[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: KOffice Lib/KDE/Qt Questions
From:       David Faure <david () mandrakesoft ! com>
Date:       2001-11-13 11:19:20
[Download RAW message or body]

On Tuesday 13 November 2001 10:54, Clarence Dang wrote:
> Hello...
> 
> As you may be aware, I'm developing an import fitler for KWord but I am 
> completely new to KOffice, Linux and KDE.  So I was wondering if anyone would 
> be able to please answer some of my questions below:
> 
> 1. It seems that I cannot call "bool KoStore::write( const char* _data, 
> unsigned long _len )" more than once.  I thought that it would have acted a 
> bit like fwrite where you can call it more than once.  I mean, if I can't 
> call it more than once, I would have to accumulate all my output into one 
> huge string and then call KoStore::write at the end.  Isn't this hopelessly 
> inefficient?

You should be able to call write() more than once, there's no reason why not.
About the efficiency and the buffering... well, when writing, KoStore has
to buffer the data anyway :(. Can't be fixed until we ditch tar.gz and go for
something like zip - reason: the tar format requires to write down the size of
the data before writing the actual data...
So what's happening exactly ? Do you get any error... ?

> 2. How do I convert a QString into a C String?  I currently use "(char *) 
> QCString (myqstring.utf8 ())" but surely there is a better way...

Depends which encoding you want....
But the above line is overkill in any case.
You want either myqstring.utf8() or myqstring.local8Bit(),
but in both case, they return a QCString already - no need for anything
else, it automatically casts into a char* if you need that.

Here's what I wrote about encodings in an earlier mail to kde-core-devel:
"QString is always unicode, i.e. encoding-independent representation (16 bit).
 QCString or char * is encoding-dependent 8 bit data... When converting from a 
QString to a QCString (or char*), you have to choose which encoding you want
 to use. This can be latin1 (for system paths, like /etc or any other internal stuff),
 utf8 (a 8-bit representation that can encode any unicode string),
 or local8Bit - which is the locale-dependent 8-bit representation, the one
 which isn't the same depending on the locale (country, if you want, roughly speaking).
 But it's also the one that users want to see (in their files etc.), that filesystems use,
 and that legacy applications use.
 
And when going from QCString (or char *) to QString, you have to make the
 same choice, to decide between fromLatin1 (default), fromUtf8, or fromLocal8Bit().
 
For filenames you can use QFile::encodeName() and QFile::decodeName(), but
 this simply calls local8Bit and fromLocal8Bit, since all filesystems are
 using the locale-8-bit encoding up to now.
 
So: always be careful when copying data from char * to QString or the other
 way round. If you look at the patch, you'll see it was mostly about that.
 And about having NO conversion when putting a QString into a QString, obviously !
 "

> 3. The ASCII Import filter has a line something like "KoStore out = KoStore 
> (QString (outfilename), KoStore::Write);".  This would be equivalent to:
> 
> KoStore out ();
> out = KoStore (QString (outfilename), KoStore::Write);
> 
> Why doesn't this "equivalent" version compile?

C++ is full of tricks. The line is rather equivalent to
KoStore out(QString (outfilename), KoStore::Write);
i.e. a call to a constructor with 2 arguments.
Your "[not-so-]equivalent" version calls a constructor with 0 arguments, which
it doesn't have.

> 4. With kdDebug() and friends, how do I "register" a debug area with KDE i.e. 
> so that I can call kdDebug(mydebugarea) for my particular filter (mswrite)?
Adding the entry to kdelibs/kdecore/kdebug.areas.

-- 
David FAURE, david@mandrakesoft.com, faure@kde.org
http://perso.mandrakesoft.com/~david/ , http://www.konqueror.org/
KDE 3.0: Konquering the Desktops
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic