在Qt 5中嵌入Python [英] Embedding Python in Qt 5

查看:1749
本文介绍了在Qt 5中嵌入Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想嵌入Python解释器到一个Qt 5应用程序。

I would like to embed Python interpreter in to a Qt 5 application.

我有一个工作的应用程序在Qt 5,但当我把

I have a working application in Qt 5 but when I put

#include <Python.h>

在顶部(Qt标题下)编译打破

at the top (below Qt headers) the compilation breaks with

../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定义了一些常用的单词?

Please, does anyone know why this happens? I could be because Qt and Python define some common words? What can I do about it?

推荐答案

这是因为包括Python.h首先间接包含termios.h,它定义了B0是0,这反过来qpagedpaintdevice.h想要用作一个变量名称。包括Python.h之后的Qt包含了几乎相同的事情,反过来与字符串'槽'。

This happens because including Python.h first indirectly includes termios.h, which defines B0 to be 0, which in turn qpagedpaintdevice.h want's to use as a variable name. Including Python.h after the Qt includes does pretty much the same thing the other way around with the string 'slots'.

我建议以下顺序:

#include <Python.h>
#undef B0
#include <QWhatEver>

这篇关于在Qt 5中嵌入Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆