[PyQt] [SIP] How to reasonably implement writable global variables?
Casper Ti. Vector
caspervector at gmail.com
Fri Jul 5 12:00:51 BST 2013
[Shamelessly bumping this post in attempt to resolve this issue...
Sorry for the disturbance; won't bump again even without reply :(]
On Thu, Jul 04, 2013 at 06:21:48PM +0800, Casper Ti. Vector wrote:
> [Mistakenly sent to the author instead of the mail list, now re-sent.
> Plus, perhaps Phil can set the `Reply-To:' flag in the configuration of
> the mail list program so that replies are by default sent to the list?]
>
> Again, I found that static members of classes are read-only when used
> from the class directly, for example:
>
> test.h:
> > struct test { static int x; };
> > extern test Test;
> > int get();
> > void set(int x);
>
> test.cpp:
> > #include "test.h"
> > int test::x = 0;
> > test Test;
> > int get() { return Test.x; }
> > void set(int x) { Test.x = x; }
>
> test.sip:
> > %Module test
> > %ModuleHeaderCode
> > #include "test.h"
> > %End
> > struct test { static int x; };
> > test Test;
> > int get();
> > void set(int x);
>
> test.py:
> > import test
> > test.get() # prints 0
> > test.test.x # also prints 0
> > test.Test.x # also prints 0
> >
> > test.set(1) # set using set function
> > test.test.x # prints 1, so the [C++ -> python] data transfer
> > # succeeded.
> >
> > test.Test.x = 2 # set using instance of class
> > test.get() # prints 2, so the [python -> C++] data transfer
> > # succeeded.
> >
> > test.test.x = 3 # set using the class directly
> > test.get() # prints 2, so the [python -> C++] data transfer
> > # failed.
> > test.Test.x # prints 3, so `x' in the `test' class does not
> > # refer to its former C++ counterpart now.
>
> So is there a way to make the modifications via uninstantiated classe to
> static members available to their C++ counterparts? Thanks very much :)
--
My current OpenPGP key:
4096R/0xE18262B5D9BF213A (expires: 2017.1.1)
D69C 1828 2BF2 755D C383 D7B2 E182 62B5 D9BF 213A
More information about the PyQt
mailing list