繁体   English   中英

Python,PyQt和C ++库

[英]Python, PyQt and C++ library

我使用SIP创建一个c ++库,以便在Python代码中使用它。

我的问题是我没有设法将python QString对象传递给C ++库函数。 每次使用QString调用C ++函数都会导致Python崩溃。 执行函数时,但在启动函数的第一步之前,不会出现崩溃。 (所以我不把cpp文件放在这里)

这是我做的:

C ++类:

#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 );
};

-

sip文件:

%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 ); 
};

-

Python的用法:

>>> 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

难道我做错了什么 ? 是不是应该使用Python和C ++的方式?

-

以上初始化的另一个测试:

>>> qs1 += obj.getS1( "azert" )

给出错误:

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

这似乎表明Python没有正确理解C ++库中的QString。

如果这会让某人感兴趣,我发现问题肯定是因为PyQt提供了Qt 4.9.2(这不是公共版本),尽管我的C ++库链接了Qt 4.6.3。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM