Trolltech Home | QSA-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

QSA-interest Archive, January 2006
QSA crash when calling a slot that returns QVariant


Message 1 in thread

<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Hello,<DIV><BR class="khtml-block-placeholder"></DIV><DIV>I believe I have found a bug in QSA 1.2.0 w/ Qt 4.1.0.  I'm porting a large project from Qt 3 to Qt 4, and really giving QSA a good workout!  :)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>QSA seems to crash whenever a script calls a slot that returns a QVariant.  I've attached an example program that illustrates this.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I have also figured out a potential fix.  In the file src/kernel/quickobjects.cpp, change the qsa_default_value function to this:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>---</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">static void *qsa_default_value(QSASlotCaching *caching, const QSATypeInfo &amp;ti)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">{</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">    const QVariant *v = caching-&gt;variants(QVariant::Type(ti.id));</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">    void *const_data = (void *) v-&gt;constData();</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><FONT class="Apple-style-span" face="Helvetica" size="3"><SPAN class="Apple-style-span" style="font-size: 12px;"><BR></SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">    if (v-&gt;type() == QVariant::Invalid) {</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        if (ti.name == "QList&lt;int&gt;")</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">            return caching-&gt;intlists(QList&lt;int&gt;());</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        else if (ti.name == "QObjectList")</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">            return caching-&gt;qobjectlists(QObjectList());</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        else if (ti.name == "QVariant")  // &lt;--- These two lines fix the crash</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">            return caching-&gt;variants(QVariant());</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">        else if (ti.name.count('*') == 0 &amp;&amp; ti.name.length() &gt; 0)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">            return 0;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">    }</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; ; font-family: Monaco; font-size: 10px; "><FONT class="Apple-style-span" face="Helvetica" size="3"><SPAN class="Apple-style-span" style="font-size: 12px;"><BR></SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">    return const_data;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">}</DIV><DIV>---</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Note the added condition to checki if ti.name == "QVariant".  That seems to do the trick.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Joel Nordell</DIV><DIV>Software Engineer</DIV><DIV>ONEAC Corp.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV></DIV></BODY></HTML>

Attachment: crash.h
Description: Binary data

Attachment: crash.cpp
Description: Binary data

<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV></DIV><DIV><BR><BR class="khtml-block-placeholder"></DIV></BODY></HTML>

Message 2 in thread

Joel Nordell wrote:
> Hello,
> 
> ---
> static void *qsa_default_value(QSASlotCaching *caching, const QSATypeInfo &ti)
> {
>     const QVariant *v = caching->variants(QVariant::Type(ti.id));
>     void *const_data = (void *) v->constData();
> 
>     if (v->type() == QVariant::Invalid) {
>         if (ti.name == "QList<int>")
>             return caching->intlists(QList<int>());
>         else if (ti.name == "QObjectList")
>             return caching->qobjectlists(QObjectList());
>         else if (ti.name == "QVariant")  // <--- These two lines fix the crash
>             return caching->variants(QVariant());
>         else if (ti.name.count('*') == 0 && ti.name.length() > 0)
>             return 0;
>     }
> 
>     return const_data;

Hi Joel,

This is a known bug, and you found the right fix for it ;-)

best regards,
Gunnar

To unsubscribe - send "unsubscribe" in the subject to qsa-interest-request@xxxxxxxxxxxxx