JPEG Thumbnailer

Thiago Macieira thiago at
Tue Aug 19 23:05:42 BST 2008

Ingo Klöcker wrote:
>I know you will kill me for making the following suggestion. :-)

Yes, I will. Using boost is an major overkill for this. Much more than 
QFile, because QFile is in a library already loaded, while boost will 
require additional code being loaded.

>If QFile is too much overhead then I'd use a boost::shared_ptr with
>custom deleter [1], i.e.
>    boost::shared_ptr<FILE> fd_in( fopen(path.toLatin1().data(), "rb"),
> fclose ); if ( fd_in.get() == NULL )
>       return false;
>If you want to close the file explicitly then you call fd_in.reset().
>Otherwise you don't have to do anything.
>Reasons for doing the above:
>a) We are coding in C++, right? So let's use the power C++ provides. It
>makes no sense to write error prone code, if there's a way to avoid it.

Uh... std::fstream?

>b) Using boost::shared_ptr is just a compile time dependency.

Right, but it'll bring in all of boost's atomic reference counting code 
along. Also remember that some compilers are brain-dead and will 
instantiate the entire class, as opposed to just the parts of it that you 
actually use.

Not to mention that a custom deleter would have to be written.

What you really want here is std::auto_ptr with a custom deleter. There is 
no shared pointer in this circumstance, so no need to add the overhead 
associated with that,

>c) Several KDE packages (kdepimlibs, kdepim) do already have a
>dependency on boost.

Sometimes unwarranted. There's a lot of boost that has equivalents in Qt, 
including shared_ptr/intrusive_ptr (Qt 4.5's QSharedPointer for both). 
But there are nice things in it too.

Also, there's a very, very simple way of making sure there are 
no "returns" where you forgot to close the file: create a different 

    FILE *f = fopen(...);
    bool result = doTheWork(f);
    return result;

Remember: the only reason QFile was mentioned in this thread wasn't 
because of "forgetting to close". It was to encode the name properly from 
QString to the 8-bit format.

  Thiago Macieira  -  thiago (AT) - thiago (AT)
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list