在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
相关推荐
埃伊蟹黄面33 分钟前
计算机的“身体”与“灵魂”:冯·诺依曼架构与操作系统
linux
winner88813 小时前
Linux 软件安装 “命令密码本”:yum/apt/brew 一网打尽
linux·运维·服务器
独隅3 小时前
在 Lua 中,你可以使用 `os.date()` 函数轻松地将时间戳转换为格式化的时间字符串
开发语言·lua
思麟呀4 小时前
Linux的基础IO流
linux·运维·服务器·开发语言·c++
星释4 小时前
Rust 练习册 :Pythagorean Triplet与数学算法
开发语言·算法·rust
星释4 小时前
Rust 练习册 :Nth Prime与素数算法
开发语言·算法·rust
winner88815 小时前
嵌入式Linux驱动开发全流程:工具协作+核心概念拆解(从入门到理解)
linux·运维·驱动开发
lkbhua莱克瓦245 小时前
Java基础——集合进阶3
java·开发语言·笔记
ShiinaKaze5 小时前
fatal error: bits/c++config.h: No such file or directory
linux·gcc·g++
多喝开水少熬夜5 小时前
Trie树相关算法题java实现
java·开发语言·算法