编译器看不到 QX11Info

Compiler does not see QX11Info

本文关键字:QX11Info 看不到 编译器      更新时间:2023-10-16

我创建了一个小类来设置一些全局快捷方式。但是现在,当我编译我的应用程序时,我看到许多错误:

In file included from ../src/GlobalShortcut/globalshortcut_linux.h:7:0,
                 from moc_globalshortcut_linux.cpp:9:
../../../QtStable/5.4/gcc_64/include/QtWidgets/qstyleoption.h:117:9: error: expected identifier before numeric constant
         None = 0x00,
         ^
../../../QtStable/5.4/gcc_64/include/QtWidgets/qstyleoption.h:117:9: error: expected '}' before numeric constant
../../../QtStable/5.4/gcc_64/include/QtWidgets/qstyleoption.h:117:9: error: expected unqualified-id before numeric constant
In file included from ../../../QtStable/5.4/gcc_64/include/QtCore/qglobal.h:1085:0,
                 from ../src/GlobalShortcut/globalshortcut_linux.h:4,
                 from moc_globalshortcut_linux.cpp:9:
../../../QtStable/5.4/gcc_64/include/QtWidgets/qstyleoption.h:121:36: error: 'FrameFeature' was not declared in this scope
     Q_DECLARE_FLAGS(FrameFeatures, FrameFeature)
                                    ^

当我发表评论时,我的类错误消失了。这是:http://pastebin.com/k5qSvqDn

好的,我从QWidget而不是QMainWindow继承了类(我不知道为什么:D),现在我有另一个错误:

mainwindow.o: In function `X11ShortCut::addShortCut(QKeySequence, QString)':
globalshortcut_linux.h:30: undefined reference to `QX11Info::display()'
globalshortcut_linux.h:31: undefined reference to `QX11Info::appRootWindow(int)'
globalshortcut_linux.h:31: undefined reference to `QX11Info::display()'
globalshortcut_linux.h:32: undefined reference to `QX11Info::display()'

在我的 .pro 文件中,我添加了LIBS += -lX11,它没有帮助。

那么,问题出在哪里呢?

我没有检查过,但我相信您只是错过了将以下内容添加到您的.pro文件中,如文档中所述

QT += gui x11extras

您可能缺少头文件,但是如果没有错误消息,我发现很难弄清楚,因为我从未直接接触过X11的东西。

希望对您有所帮助。

> Vinicius接近得到完整的答案。

这适用于Qt 5.1或更高版本。问题是删除了对 X11 和 GDI 句柄的访问,然后又放回了稍微不同的位置。

将 x11extras 添加到 .pro 文件:

QT += gui x11extras

如果 moc 生成的代码无法编译,请将以下内容添加到它包含的文件的底部(X11 标头定义 Bool):

#undef Bool

将以下内容添加到需要访问 QX11info 的文件中:

#include <QtX11Extras/qx11info_x11.h>