Python、PyQt和C++;图书馆 我用SIP制作了一个C++库,用python代码使用。 我的问题是,我无法把Python QStand对象传递给C++库函数。 使用QStand对C++函数的每次调用都会导致Python崩溃。 崩溃不会在执行函数时出现,而是在开始函数的第一步之前出现。(所以我不把cpp文件放在这里)

Python、PyQt和C++;图书馆 我用SIP制作了一个C++库,用python代码使用。 我的问题是,我无法把Python QStand对象传递给C++库函数。 使用QStand对C++函数的每次调用都会导致Python崩溃。 崩溃不会在执行函数时出现,而是在开始函数的第一步之前出现。(所以我不把cpp文件放在这里),c++,pyqt,C++,Pyqt,以下是我的工作: C++类: - sip文件: - Python的用法: 给出了错误: TypeError:无法连接'QString'和'ProcessError'对象 这似乎表明,Python中的C++字符串的QStand没有被正确理解。 < P>如果有兴趣,我发现问题肯定是因为PyQt提供了Qt4.92(这不是公开版本),虽然我的C++库链接了Qt4.63. #include "QString" Class CPythInteface { public: CPythInteface

以下是我的工作:

C++类:

-

sip文件:

-

Python的用法:

给出了错误:

TypeError:无法连接'QString'和'ProcessError'对象


这似乎表明,Python中的C++字符串的QStand没有被正确理解。

< P>如果有兴趣,我发现问题肯定是因为PyQt提供了Qt4.92(这不是公开版本),虽然我的C++库链接了Qt4.63.
#include "QString"

Class CPythInteface
{
 public:
  CPythInteface ();

  // Trying a lot of prototypes:`
  bool testSET( const QString* cSource);
  bool testGET( QString* Source );
  bool testGET2( QString& Source );
  bool testGET3( char* zBuff );
  bool testGET4( QString Source );
  bool testSET4( QString Source );
  QString getS1( const char* zVal );
};
%Module libtest 1
%Import QtCore/QtCoremod.sip

class CPythInteface
{

%TypeHeaderCode
#include "CPythInteface.h"
%End  

 public:

  CPythInteface ();

  bool testSET( const QString* );
  bool testGET( QString*  );
  bool testGET2( QString&  );
  bool testGET3( char*  );
  bool testGET4( QString Source );
  bool testSET4( QString Source );

  QString getS1( const char* zVal ); 
};
>>> import libtest
>>> obj = libtest. CPythInteface()
>>> from PyQt4 import QtCore
>>> qs1 = QtCore.QString( "abc" )
>>> obj.testGET3( "azertyuiop" )        <-- OK
>>> obj.testXXX( qs1 )              <-- Crashes for all 
                                       functions SET/GET
>>> qs1 += obj.getS1( "azert" )