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编译报错
根据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