I have already sent the same email to the mail list.But I can't find the mail in my inbox.I do not know whether the message is sent successfully.So I send it again.<br><br>I meet a problem in my code:<br><br>hello.h:<br>
<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">#include<QtCore><br><br>class Hello : public QObject{<br>
Q_OBJECT<br>public:<br> Hello(QObject *parent = 0);<br> static int test(){<br> static int i=0;<br> qDebug()<<i++;<br> return 0;<br> }<br>};<br></blockquote><br>hello.cpp:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
#include "hello.h"<br><br>const int i=Hello::test();<br><br>Hello::Hello (QObject *parent)<br>{<br>}<br></blockquote><br clear="all">hello.sip<br><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
%Module hello<br><br>%Import QtCore/QtCoremod.sip<br><br><br>class Hello : public QObject {<br><br>%TypeHeaderCode<br>#include "hello.h"<br>%End<br><br>public:<br> Hello(QObject *parent = 0);<br> static int test();<br>
};<br></blockquote><br>I use the<i> const int i=Hello::test();</i> to invoke test() before <i>main</i> function.It's uesful in <span>factory pattern when you want to auto </span><span>
</span>register driver.<br><br>the python test code<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">import hello<br>hello.Hello.test1()<br></blockquote>
<br>It seems <i>static int i</i> in <i>test() </i>changed after <i>import hello</i><br><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">Breakpoint 1, Hello::test1 () at hello.h:8<br>
8 static int test1(){<br>(gdb) p i<br>$1 = 0<br>(gdb) p &i<br>$2 = (const int *) 0x7ffff60300d0<br>(gdb) c<br>Continuing.<br>0 <br><br>Breakpoint 1, Hello::test1 () at main.h:8<br>8 static int test1(){<br>
(gdb) p &i<br>$3 = (const int *) 0x7ffff60300d0<br>(gdb) n<br>10 qDebug()<<i++;<br>(gdb) p &i<br>$4 = (int *) 0x7ffff62355c0 <---What happen here?<br></blockquote><br>in siphelloHello.cpp:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">extern "C" {static PyObject *meth_Hello_test1(PyObject *, PyObject *);}<br>static PyObject *meth_Hello_test1(PyObject *, PyObject *sipArgs)<br>
{<br> PyObject *sipParseErr = NULL;<br><br> {<br> if (sipParseArgs(&sipParseErr, sipArgs, ""))<br> {<br> int sipRes;<br><br> Py_BEGIN_ALLOW_THREADS<br> sipRes = Hello::test1(); <br>
Py_END_ALLOW_THREADS<br><br> return SIPLong_FromLong(sipRes);<br> }<br> }<br><br> /* Raise an exception if the arguments couldn't be parsed. */<br> sipNoMethod(sipParseErr, sipName_Hello, sipName_test1, NULL);<br>
<br> return NULL;<br>}<br></blockquote><br>the <i>Hello</i> object in the siphelloHello.cpp is<span lang="en"><span> different</span></span> from <br><i>const int i=Hello::test();</i> <br>
<br><br>Thx for reading.<span><font color="#888888"><br>
</font></span><br clear="all"><br>-- <br> <br><br>DY.Feng(叶毅锋)<br>yyfeng88625@twitter<br>Department of Applied Mathematics<br>Guangzhou University,China<br><a href="mailto:dyfeng@stu.gzhu.edu.cn" target="_blank">dyfeng@stu.gzhu.edu.cn</a><br>
<br>