[PyQt] DOUBTT

V. Armando Sole sole at esrf.fr
Wed Jul 23 23:23:11 BST 2014


I let the sip experts to answer your question.

Depending on the complexity of the library, you may want to take a look 
at Cython. That would allow to remove any dependency on sip because the 
generated code does not any longer depend on Cython. If one can achieve 
the same without depending on the installed sip version, then you can 
forget about my comment.

Armando

On 23.07.2014 23:59, Amey Patil wrote:
> Hi,
> I am at the basic level in using sip wrapper in python. I have written
> a small library in c++ and wrapping it in sip for execution in Python.
> Copy pasting my entire files for better understanding. Also pasting
> the output from the terminal, the behaviour i am getting is completely
> unexpected, can you please look into it...
> 
> WORD.H:
> 
> class Word
> {
> 
> public:
>     int integer;
>     const char *name;
>     Word();
>     void set_name(const char *a);
>      void reset_name();
>     const char *get_name();
> };
> 
> WORD.CPP:
> 
> #include <iostream>
>  #include "word.h"
> 
> using namespace std;
> 
> Word::Word(){
>     name = "PyQt";
> 
> }
> 
> void Word::set_name(const char *a){
>     cout << "parameter passed to set_name is " << a << endl;
>      cout << "name before set_name is " << name << endl;
>     name = a;
>     cout << "name after set_name is " << name << endl;
> }
> 
> void Word::reset_name(){
>      cout << "name before reset_name is " << name << endl;
>     const char *x = "Epics";
>     name = x;
>     cout << "name after reset_name is " << name << endl;
>  }
> 
> const char *Word::get_name(){
>     cout << "name before get_name is " << name << endl;
>     return name;
> }
> 
> WORD.SIP:
> 
>  %Module word
> 
> class Word
> {
> 
> %TypeHeaderCode
> #include <word.h>
> %End
> 
> public:
>     int integer;
>     const char *name;
>     Word();
>     void set_name(const char *a);
>     void reset_name();
>      const char *get_name();
> };
> 
> OUTPUT IN PYTHON (TERMINAL):
> 
>>>> import word
>>>> w = word.Word()
>  >>> w.get_name()
> name before get_name is PyQt
> 'PyQt'
>>>> w.set_name("Amey")
> parameter passed to set_name is Amey
> name before set_name is PyQt
> name after set_name is Amey
>  >>> w.get_name()
> name before get_name is
> ''
>>>> w.reset_name()
> name before reset_name is <stdin>
>  name after reset_name is Epics
>>>> w.get_name()
> name before get_name is Epics
> 'Epics'
> 
> PROBLEMS:
> 
> 1. It won't print the output when i call get_name() after calling
> set_name().
>  2. As you can see in the output, I am editing nothing between the
> highlighted lines, still the output shows nothing in one while <stdin>
> in other.
> 
> Please tell me what's wrong.
> 
> Looking forward for your reply,
> 
> Sincere Regards,
> Amey Patil
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list