编译器没有看到QX11Info

时间:2015-02-01 23:58:20

标签: c++ qt x11

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

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,它没有帮助。

那么,问题是什么?

2 个答案:

答案 0 :(得分:3)

我没有选中,但我相信您只是错过了将以下内容添加到.pro文件中,如docs

所述
QT += gui x11extras

你可能错过了一个头文件,但没有错误信息,我觉得有点难以弄明白,因为我从来没有直接触及过X11的东西。

希望它有所帮助。

答案 1 :(得分:2)

Vinicius即将获得完整答案。

这适用于Qt 5.1或更新版本。问题是删除了对X11和GDI句柄的访问权限,然后再将它们放回到稍微不同的地方。

将x11extras添加到.pro文件中:

QT += gui x11extras

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

#undef Bool

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

#include <QtX11Extras/qx11info_x11.h>