概述
#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 ';'
这与此问题非常相似,但解决方案无效
谁知道如何解决这个问题?或建议一些干净的解决方法,以便python.h和Qt5
以后能幸福地生活在一起吗?
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.
总结
以上是编程之家为你收集整理的在Qt 5中嵌入Python3全部内容,希望文章能够帮你解决在Qt 5中嵌入Python3所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧