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

List:       kde-core-devel
Subject:    Re: readEntry and booleans
From:       Thomas Braxton <brax108 () cox ! net>
Date:       2006-01-04 18:11:24
Message-ID: 200601041211.24553.brax108 () cox ! net
[Download RAW message or body]

On Wednesday 04 January 2006 05:04, André Wöbbeking wrote:
> 1) can we check if the QVariant is convertable (see
> qVariantCanConvert()) at least for debug code?

how about something like this patch? I'm not sure if I should use convert or 
canConvert. It seems that canConvert only checks if the conversion is 
possible & convert checks if the conversion fails. I need to look at the Qt 
code a little more closely to see what to do.

["diff" (text/x-diff)]

Index: kconfigbase.h
===================================================================
--- kconfigbase.h	(revision 494324)
+++ kconfigbase.h	(working copy)
@@ -1603,8 +1603,11 @@
 
   QList<T> list;
   if (!vList.isEmpty()) {
-    foreach (QVariant aValue, vList)
+    QVariant::Type wanted = QVariant(T()).type();
+    foreach (QVariant aValue, vList) {
+      Q_ASSERT(aValue.convert(wanted));
       list.append( qvariant_cast<T>(aValue) );
+    }
   }
 
   return list;
@@ -1614,6 +1617,7 @@
 void KConfigBase::writeEntry( const char* pKey, const QList<T>& rValue,
                               bool bPersistent, bool bGlobal, bool bNLS )
 {
+  Q_ASSERT(!rValue.isEmpty() && QVariant(rValue.first()).convert(QVariant::String));
   QVariantList vList;
   foreach(T aValue, rValue)
     vList.append(aValue);


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

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