[PyQt] A gobal variable problem in sip
D.Y Feng
yyfeng88625 at gmail.com
Tue Oct 23 23:11:13 BST 2012
I meet a problem in my code:
hello.h:
#include<QtCore>
>
> class Hello : public QObject{
> Q_OBJECT
> public:
> Hello(QObject *parent = 0);
> static int test(){
> static int i=0;
> qDebug()<<i++;
> return 0;
> }
> };
>
hello.cpp:
> #include "hello.h"
>
> const int i=Hello::test();
>
> Hello::Hello (QObject *parent)
> {
> }
>
hello.sip
%Module hello
>
> %Import QtCore/QtCoremod.sip
>
>
> class Hello : public QObject {
>
> %TypeHeaderCode
> #include "hello.h"
> %End
>
> public:
> Hello(QObject *parent = 0);
> static int test();
> };
>
I use the* const int i=Hello::test();* to invoke test() before
*main*function.It's uesful in factory
pattern when you want to auto register driver.
the python test code
> import hello
> hello.Hello.test1()
>
It seems *static int i* in *test() *changed after *import hello*
Breakpoint 1, Hello::test1 () at hello.h:8
> 8 static int test1(){
> (gdb) p i
> $1 = 0
> (gdb) p &i
> $2 = (const int *) 0x7ffff60300d0
> (gdb) c
> Continuing.
> 0
>
> Breakpoint 1, Hello::test1 () at main.h:8
> 8 static int test1(){
> (gdb) p &i
> $3 = (const int *) 0x7ffff60300d0
> (gdb) n
> 10 qDebug()<<i++;
> (gdb) p &i
> $4 = (int *) 0x7ffff62355c0 <---What happen here?
>
Thx for reading.
--
DY.Feng(叶毅锋)
yyfeng88625 at twitter
Department of Applied Mathematics
Guangzhou University,China
dyfeng at stu.gzhu.edu.cn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121024/c04d4233/attachment-0001.html>
More information about the PyQt
mailing list