3

Python コードで使用するために SIP で c++ ライブラリを作成します。

私の問題は、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' オブジェクトを連結できません

これは、C++ ライブラリの QString が Python によって正しく認識されていないことを示しているようです。

4

1 に答える 1

2

これが誰かの興味を引く場合に備えて、私の C++ ライブラリは Qt 4.6.3 をリンクしていましたが、PyQt が Qt 4.9.2 (これは公開バージョンではありません) で提供されたため、間違いなく問題であることがわかりました。

于 2013-05-28T12:45:42.183 に答える