我想将
Python解释器3.4嵌入到Qt 5.2.1应用程序(64位)中.
但是我有构建问题,我的意思是当我在main.cpp中包含Python头时它编译得很好.
但是我有构建问题,我的意思是当我在main.cpp中包含Python头时它编译得很好.
#include <python.h> #include "mainwindow.h" #include <QApplication> int main(int argc,char *argv[]) { QApplication a(argc,argv); MainWindow w; w.show(); return a.exec(); }
但是当我把它放在其他地方时(在Qt标题之后)
// // embedpytest.cpp // #include <QLibrary> #include <python.h> EmbedPyTest::EmbedPyTest() { }
我得到编译错误:
C:\Python34\include\object.h:435: error: C2059: Syntax error : ';' C:\Python34\include\object.h:435: error: C2238: unexpected token(s) preceding ';'
这与此问题非常相似,但解决方案无效
解决方法
违规行是这样的:
PyType_Slot *slots; /* terminated by slot==0. */
问题是,对于这一行,“slot”在Qt中默认是一个关键字.要在其他项目中使用该变量名,您需要在项目文件中使用它:
CONFIG += no_keywords
有关详细信息,请参阅documentation:
Using Qt with 3rd Party Signals and Slots
It is possible to use Qt with a 3rd party signal/slot mechanism. You can even use both mechanisms in the same project. Just add the following line to your qmake project (.pro) file.
CONFIG += no_keywords
It tells Qt not to define the moc keywords signals,slots,and emit,because these names will be used by a 3rd party library,e.g. Boost. Then to continue using Qt signals and slots with the no_keywords flag,simply replace all uses of the Qt moc keywords in your sources with the corresponding Qt macros Q_SIGNALS (or Q_SIGNAL),Q_SLOTS (or Q_SLOT),and Q_EMIT.