Qt C++与Python混合编程:补充错误
在提示中,需要引用Python.h,出现错误。
1、找不到Python.h
如果是pro工程,需要在里面配置;
INCLUDEPATH += /Users/xinnianwang/opt/anaconda3/include
LIBS += /Users/xinnianwang/opt/anaconda3/lib
如果是CMakeLists.txt需要配置
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(testHpy ${PYTHON_LIBRARIES})
2、会出现object.h中的参数错误。
因为slots和qT中的slots关键词矛盾。
error: expected member name or ';' after declaration specifiers PyType_Slot *slots; /* terminated by slot==0. */ ~~~~~~~~~~~ ^
需要在头文件中使用
#undef slots
#include <python3.9/Python.h>
#define slots Q_SLOTS