QT+C++、Python.h ファイルをインポート

第一歩

必要に応じて QT を開き、新しいプロジェクトを作成し、.pro ファイルを編集します。

INCLUDEPATH += C:\Users\Administrator\AppData\Local\Programs\Python\PythonXX\include
LIBS += -LC:\Users\Administrator\AppData\Local\Programs\Python\PythonXX\libs -lpythonXX

上記の 2 行のコードを .pro ファイルに書き込み、XX の位置を独自の Python バージョンに置き換えます。

ステップ2

テスト:
.cpp ファイルにヘッダー ファイル test を入力します。

#include<Python.h>

エラーを報告する

私の側では、次の 2 つのエラーが表示されます。
エラー 1:

:error: expected unqualified-id before ';' token
     PyType_Slot *slots; /* terminated by slot==0. */
                       ^

エラー 2:

 error: '::hypot' has not been declared
   using ::hypot;

Python.h のメソッドが cmath のメソッドと同じ名前であるため、このようなエラーが発生するようですが、コードを次の状況に変更すると解決します。

#include "model.h"
#include "ui_model.h"
#include <cmath>
#define _hypot hypot
#undef slots
#include<Python.h>

つまり、問題を解決するには、#include<Python.h> の前に #include、#define _hypot hypert、#undef スロットを追加します。

おすすめ

転載: blog.csdn.net/weixin_45866980/article/details/130240898