QVariant weirdness with KUrl

Andreas Pakulat apaku at gmx.de
Mon Apr 2 00:32:48 BST 2007


Hi,

today I encountered that KConfigGroup can still not read/write KUrl
entries. So I had a look and found something weird:

QVariant( KUrl( "file:///home/" ) ).type() == QVariant::Url

which means the above QVariant will return false on canConvert<KUrl>()
and will return an empty string for value<KUrl>(). 

I guess the problem here is that KUrl subclasses from QUrl, but I'm of
course not sure. Can somebody please look into this so
KConfigGroup::readEntry( const char* pKey, const QVariant&) const; 
can be adjusted accordingly to work with KUrl.

Meanwhile, here's a patch to allow KConfigGroup to read/write QUrl's
using their string representation. Ok to commit?

Andreas

-- 
If you can read this, you're too close.
-------------- next part --------------
Index: kconfiggroup.cpp
===================================================================
--- kconfiggroup.cpp	(Revision 647263)
+++ kconfiggroup.cpp	(Arbeitskopie)
@@ -553,6 +553,10 @@ QVariant KConfigGroup::readEntry( const 
                  << "' but kdeui isn't linked! If it is linked to your program, this is a platform bug. "
                     "Please inform the KDE developers" << endl;
         break;
+      case QVariant::Url: {
+          const QUrl url( readEntry( pKey, aDefault.toUrl().toString() ) );
+          return url;
+      }
 
       default:
           break;
@@ -910,7 +914,9 @@ void KConfigGroup::writeEntry ( const ch
                  << "' but kdeui isn't linked! If it is linked to your program, this is a platform bug. "
                     "Please inform the KDE developers" << endl;
         break;
-
+    case QVariant::Url:
+        writeEntry( pKey, prop.toUrl().toString(), pFlags );
+        return;
     case QVariant::Pixmap:
     case QVariant::Image:
     case QVariant::Brush:


More information about the kde-core-devel mailing list