C++在Qt中使用Python报错

在尝试在Qt5项目中使用C++导入Python头文件时遇到错误,错误源于Python.h和Qt的qpagedpaintdevice.h之间的命名冲突。解决方案是通过在包含Python.h之前或之后定义并取消定义'slots'来避免冲突,然后重新构建项目以解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一. 导入头文件报错

In included file: expected member name or ‘;’ after declaration specifiers object.h:227:23: error occurred here
在这里插入图片描述



原因:

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’.



解决

  1. 双击错误打开文件 object.h 文件
    在这里插入图片描述

  2. 把冲突的slots 使用undef 和define

 PyType_Slot *slots; /* terminated by slot==0. */
 更改为
 #undef slots
 PyType_Slot *slots; /* terminated by slot&#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值