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

List:       kde-commits
Subject:    Re: kdepim/kmailcvt
From:       Marc Mutz <marc () klaralvdalens-datakonsult ! se>
Date:       2005-04-15 5:20:59
Message-ID: 200504150721.00977.marc () klaralvdalens-datakonsult ! se
[Download RAW message or body]

On Thursday 14 April 2005 22:42, Danny Kukawka wrote:
> +                    hierarch.close();

If a QFile is destroyed, it's closed automatically. It's fine to call 
QFile::close() when you're not needing the file open anymore, but the Qfile 
instance will be kept around for a while, but when the function has multiple 
return paths, adding a file.close() in front of each just impairs 
readability. If you really, really want it explicit, then use

class QFileCloser {
  QFile & mFile;
public:
  QFileCloser( QFile & file ) : mFile( file ) {}
  ~QFileCloser() { if ( mFile.isOpen() ) mFile.close(); }
};

int myFunc() {
  ...
  QFile file( ... );
  QFileCloser closer( file );
 ...
    return false;
  return true;
}

Marc

-- 
Marc Mutz -- marc@klaralvdalens-datakonsult.se, mutz@kde.org
phone: +49 521 521 45 45; mobile: +49 177 32 94 700
Klarälvdalens Datakonsult AB, Platform-independent software solutions


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

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