在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
相关推荐
郭式云源生法则1 小时前
归档及压缩、重定向与管道操作和综合使用,find精确查找、find处理查找结果、vim高级使用、vimdiff多文件使用
linux·运维·服务器
R-G-B1 小时前
【02】C#入门到精通——C# 变量、输入/输出、类型转换
开发语言·c#·c# 变量·c#输入/输出·c#类型转换
星河队长1 小时前
C# 软件加密方法,有使用时间限制,同时要防止拷贝
开发语言·c#
史迪奇_xxx1 小时前
10、一个简易 vector:C++ 模板与 STL
java·开发语言·c++
一张假钞1 小时前
Ubuntu 24.04 安装 Jenkins
linux·ci/cd·jenkins
2301_801252221 小时前
Java中的反射
java·开发语言
Kiri霧2 小时前
Rust开发环境搭建
开发语言·后端·rust
tuokuac2 小时前
查看你电脑上某个端口正在被哪个进程占用
linux
weixin-a153003083162 小时前
[数据抓取-1]beautifulsoup
开发语言·python·beautifulsoup
MANONGMN2 小时前
Linux 通配符与正则表达式(含实战案例+避坑指南)
linux·运维·正则表达式