在qt5中使用XShapeCombineRectangles编译报错

linux x11环境中,在qt5中使用XShapeCombineRectangles去实现鼠标穿透

引用了两个头文件:

c++ 复制代码
#include <QX11Info>
#include <X11/extensions/shape.h>

编译的时候会报错:

Desktop_Qt_5_12_12_GCC_64bit-Debug/moc_mainwindow.cpp:86: error: expected unqualified-id before 'int'

In file included from /usr/include/X11/Xutil.h:53,

from /usr/include/X11/extensions/shape.h:34,

from .../tablet/mainwindow.h:58,

from moc_mainwindow.cpp:9:

moc_mainwindow.cpp:86:33: error: expected unqualified-id before 'int'

86 | QMetaType::Void, QMetaType::Bool, 9,

| ^~~~

根据报错信息,可查到是x11/xlib.h这个库中使用define定义了一些类型导致qt编译报错

https://stackoverflow.com/questions/22476110/c-compiling-error-including-x11-x-h-x11-xlib-h/41837372#41837372

根据stackoverflow中的答案,去掉用宏定义的类型即可成功编译:

c++ 复制代码
#include <QX11Info>
#include <X11/extensions/shape.h>

#undef Bool
#undef CursorShape
#undef Expose
#undef KeyPress
#undef KeyRelease
#undef FocusIn
#undef FocusOut
#undef FontChange
#undef None
#undef Status
#undef Unsorted
相关推荐
_OP_CHEN几秒前
【从零开始的Qt开发指南】(十四)Qt 窗口之“三剑客”:工具栏、状态栏、浮动窗口进阶实战指南
开发语言·c++·qt·前端开发·gui开发·qt窗口
古城小栈1 分钟前
Rust 模块管理与文件联动
开发语言·后端·rust
知识分享小能手4 分钟前
Ubuntu入门学习教程,从入门到精通, Ubuntu 22.04中的任务计划详解(16)
linux·学习·ubuntu
会算数的⑨9 分钟前
Java场景化面经分享(一)—— JVM有关
java·开发语言·jvm·后端·面试
oMcLin9 分钟前
CentOS 7.9 使用 SELinux 时无法访问特定目录:如何配置 SELinux 策略允许访问
linux·运维·centos
葵花楹12 分钟前
【JAVA期末复习】
java·开发语言·排序算法
一叶之秋141216 分钟前
QT常用控件(二)
开发语言·qt
QT 小鲜肉17 分钟前
【Linux命令大全】001.文件管理之whereis命令(实操篇)
linux·运维·服务器·网络·笔记
nuowenyadelunwen17 分钟前
Harvard CS50 Week 6 Python
开发语言·python
饼干,19 分钟前
期末考试3
开发语言·人工智能·python