QVariant weirdness with KUrl

Andreas Pakulat apaku at gmx.de
Mon Apr 2 11:18:58 BST 2007


On 02.04.07 12:01:39, David Faure wrote:
> On Monday 02 April 2007, Andreas Pakulat wrote:
> > 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?
> 
> Please never use QUrl::toString(), it breaks in some cases (e.g. paths with a '#' in them).
> Use KUrl(theQUrl).url().

I knew there is a reason why url() exists. Here's an update patch. Any
other objections?

Andreas

-- 
Try to relax and enjoy the crisis.
		-- Ashleigh Brilliant
-------------- 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, KUrl( aDefault.toUrl() ).url() ) );
+          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, KUrl( prop.toUrl() ).url(), pFlags );
+        return;
     case QVariant::Pixmap:
     case QVariant::Image:
     case QVariant::Brush:


More information about the kde-core-devel mailing list