您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Qt 5中嵌入Python3

5b51 2022/1/14 8:23:32 python 字数 3280 阅读 601 来源 www.jb51.cc/python

我想将 Python解释器3.4嵌入到Qt 5.2.1应用程序(64位)中. 但是我有构建问题,我的意思是当我在main.cpp中包含Python头时它编译得很好. #include <python.h> #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplicatio

概述

#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 ';'

这与此问题非常相似,但解决方案无效

Embedding Python in Qt 5

谁知道如何解决这个问题?或建议一些干净的解决方法,以便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所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶