[Qtscript-bindings] msvc: qscriptvalue_cast problems

Kent Hansen khansen at trolltech.com
Wed Jan 7 13:15:17 CET 2009


syntheticpp at gmx.net wrote:
> Building qtscriptgenerator with Qt4.5-beta1 and msvc8/msvc9sp1 SP1 does not work:
>
>  error C2440: 'default argument' : cannot convert from 'T *' to 'QVariant *'
>
> due to this template specialization:
>
> template<typename T>
> T qscriptvalue_cast(const QScriptValue &value, T * = 0)
> {...}
>
> template <>
> inline QVariant qscriptvalue_cast<QVariant>(const QScriptValue &value, QVariant *)
> {
>     return value.toVariant();
> }
>
>
> A workaround is
>
> diff --git a/qscriptengine.h b/qscriptengine.h
> index 205ed9b..0098b68 100644
> --- a/qscriptengine.h
> +++ b/qscriptengine.h
> @@ -359,8 +359,12 @@ inline bool qscriptvalue_cast_helper(const QScriptValue &value, int type, void *
>  template<typename T>
>  T qscriptvalue_cast(const QScriptValue &value
>  #ifndef Q_QDOC
> +#ifdef Q_CC_MSVC_NET
> +, T * = (T*) 0
> +#else
>  , T * = 0
>  #endif
> +#endif
>      )
>  {
>      T t;
>
>
> Any ideas if this is a compiler bug or just invalid C++?
>
> Peter
>   


Hi,
There's a patch that didn't make it into the beta, could you give it a try?

diff --git a/src/script/qscriptengine.h b/src/script/qscriptengine.h
index f293325..9d2412e 100644
--- a/src/script/qscriptengine.h
+++ b/src/script/qscriptengine.h
@@ -333,7 +333,7 @@ inline bool qscriptvalue_cast_helper(const
QScriptValue &value, int type, void *

 template<typename T>
 T qscriptvalue_cast(const QScriptValue &value
-#ifndef Q_QDOC
+#if !defined qdoc && defined Q_CC_MSVC && _MSC_VER < 1300
 , T * = 0
 #endif
     )
@@ -349,11 +349,13 @@ T qscriptvalue_cast(const QScriptValue &value
     return T();
 }

+#if !defined Q_CC_MSVC || _MSC_VER >= 1300
 template <>
-inline QVariant qscriptvalue_cast<QVariant>(const QScriptValue &value,
QVariant *)
+inline QVariant qscriptvalue_cast<QVariant>(const QScriptValue &value)
 {
     return value.toVariant();
 }
+#endif

 template <typename T>
 inline T qScriptValueToValue(const QScriptValue &value)



More information about the Qtscript-bindings mailing list