【问题标题】:Use CGEvent with Qt on Mac Os X在 Mac Os X 上使用 CGEvent 和 Qt
【发布时间】:2011-04-28 11:37:35
【问题描述】:

我需要在我的 Qt 应用程序上模拟 keyPress(我在 mac Os X 10.6 上)。

我写了这段代码:

#include <ApplicationServices/ApplicationServices.h>
...
CGEventRef mkey = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)46, true);
CGEventPost(kCGAnnotatedSessionEventTap, mkey);
CFRelease(mkey);
...

但是有一个错误:

Undefined symbols:
  "_CGEventCreateKeyboardEvent", referenced from:
      SimuleEvent::PressControl(QString)       in simuleevent.o
  "_CGEventPost", referenced from:
      SimuleEvent::PressControl(QString)       in simuleevent.o
  "_CFRelease", referenced from:
      SimuleEvent::PressControl(QString)       in simuleevent.o

我想我必须链接一个库,但我不知道是哪个?

谢谢

尼哥

【问题讨论】:

    标签: c++ qt events macos


    【解决方案1】:

    将此行添加到您的 .pro 文件中:

    LIBS += -framework ApplicationServices
    

    【讨论】:

      【解决方案2】:

      您需要链接应用程序服务框架。例如,

      clang -framework ApplicationServices yoursourcefile.c
      

      -framework 是链接器标志)

      【讨论】:

        猜你喜欢
        • 2013-11-05
        • 1970-01-01
        • 1970-01-01
        • 2013-04-27
        • 2016-03-04
        • 1970-01-01
        • 1970-01-01
        • 2012-02-29
        • 1970-01-01
        相关资源
        最近更新 更多