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

List:       kde-core-devel
Subject:    fix KSaveFile::open
From:       Matthias Kretz <kretz () kde ! org>
Date:       2007-11-19 10:31:56
Message-ID: 200711191131.57090.kretz () kde ! org
[Download RAW message or body]


Hi,

as -Woverloaded-virtual hinted, KSaveFile hides the virtual open(OpenMode) 
function (from QIODevice) and "replaces" it with a open() function. As long 
as code is only using the KSaveFile interface everything's fine, but consider 
a place where code like this

  QFile *device = new QFile(filename);
  saveToDevice(device);
....
void saveToDevice(QIODevice *device)
{
  device->open(QIODevice::WriteOnly | QIODevice::Truncate);
  ...

is changed to

  QFile *device = new KSaveFile(filename);
  saveToDevice(device);

After all KSaveFile is advertised as a QFile drop-in replacement. The pasted 
patch makes sure that a call to the virtual open function will work with a 
KSaveFile object regardless of the interface you're looking at.

Ok, to commit? (And yes, I'll add dox)

Index: io/ksavefile.cpp
===================================================================
--- io/ksavefile.cpp    (revision 738067)
+++ io/ksavefile.cpp    (working copy)
@@ -78,6 +78,11 @@

 bool KSaveFile::open()
 {
+    return open(QIODevice::ReadWrite);
+}
+
+bool KSaveFile::open(OpenMode flags)
+{
     if ( d->realFileName.isNull() ) {
         d->error=QFile::OpenError;
         d->errorString=i18n("No target filename has been given.");
@@ -131,7 +136,7 @@

     //Open oursleves with the temporary file
     QFile::setFileName(tempFile.fileName());
-    if ( !QFile::open(QIODevice::ReadWrite) ) {
+    if (!QFile::open(flags)) {
         tempFile.setAutoRemove(true);
         return false;
     }
Index: io/ksavefile.h
===================================================================
--- io/ksavefile.h      (revision 738067)
+++ io/ksavefile.h      (working copy)
@@ -154,6 +154,7 @@
      * @return true if successful, or false if an error has occurred.
      */
     bool open();
+    bool open(OpenMode flags);

     /**
      * @brief Discard changes without affecting the target file.

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz@gmx.net, kretz@kde.org,
Matthias.Kretz@urz.uni-heidelberg.de

["signature.asc" (application/pgp-signature)]

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

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