在qt5中嵌入Python
我想将Python解释器嵌入到Qt5应用程序中 我在Qt5中有一个工作应用程序,但是当我在qt5中嵌入Python,python,qt,compiler-errors,python-embedding,Python,Qt,Compiler Errors,Python Embedding,我想将Python解释器嵌入到Qt5应用程序中 我在Qt5中有一个工作应用程序,但是当我 #include <Python.h> 当我将Python头放在Qt头之上时,它会随着 ../sample/python3.3m/object.h:432:23: error: expected member name or ';' after declaration specifiers PyType_Slot *slots; /* terminated by slot==0. */ ~~~
#include <Python.h>
当我将Python头放在Qt头之上时,它会随着
../sample/python3.3m/object.h:432:23: error: expected member name or ';' after declaration specifiers
PyType_Slot *slots; /* terminated by slot==0. */
~~~~~~~~~~~ ^
In file included from ../Qt5.0.1/5.0.1/clang_64/include/QtGui/QtGui:59:
../Qt5.0.1/5.0.1/clang_64/include/QtGui/qpagedpaintdevice.h:63:57: error: expected '}'
A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
^
/usr/include/sys/termios.h:293:12: note: expanded from macro 'B0'
#define B0 0
^
../Qt5.0.1/5.0.1/clang_64/include/QtGui/qpagedpaintdevice.h:62:19: note: to match this '{'
enum PageSize { A4, B5, Letter, Legal, Executive,
^
1 error generated.
拜托,有人知道为什么会这样吗?我可能是因为Qt和Python定义了一些常用词?对此我能做些什么?之所以会发生这种情况,是因为包括Python.h首先间接地包括termios.h,它将B0定义为0,而qpagedpaintdevice.h希望将其用作变量名。在Qt includes之后包含Python.h与字符串“slots”做的事情基本相同 我建议的顺序如下:
#include <Python.h>
#undef B0
#include <QWhatEver>
#包括
#undef B0
#包括
可接受答案的替代方案:
由于Qt使用slots
作为保留关键字,因此与pythonapi中PyType_Spec
结构的slots
成员的声明存在冲突
可以指示Qt不要使用普通moc关键字,这将删除碰撞。可通过将以下内容添加到项目文件来完成此操作:
CONFIG+=无_关键字
缺点是您需要引用相应的Qt宏,而不是前面的关键字
因此,Qt侧需要进行以下更换:
信号->Q_信号
插槽->Q_插槽
发射->Q_发射
本节中有关信号和插槽的Qt文档对此进行了解释
PS:在启动一个新项目时,这通常是一个很好的选择,而不是在将Python添加到大量使用Qt关键字的现有代码库时 如果您没有使用qmake,请参阅如何设置no关键字选项。不幸的是,这对我不起作用,因为我正在开发一个Qt插件,并且许多文件已经包含Qt头。此解决方案最适合我的用例: