【问题标题】:How to process notifications from NSNotificationCenter in QT application?如何在 QT 应用程序中处理来自 NSNotificationCenter 的通知?
【发布时间】:2013-07-02 12:20:33
【问题描述】:

有一个简单的 QT 控制台应用程序,带有 QCoreApplication。 是否可以在另一个线程中处理来自通知中心的通知?例如创建一个线程并连接该线程的循环来处理通知?或扩展 QT 应用程序以向我发送此通知?

【问题讨论】:

    标签: objective-c macos qt


    【解决方案1】:

    Qt 本身的源代码中有很多例子。(我在这里做了“git grep NSNotificationCenter”。)

    至少您可以检查如下解决方案: https://github.com/qtproject/qtbase/blob/stable/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm

    L105-L109:

    [[NSNotificationCenter defaultCenter]
                addObserver:self
                   selector:@selector(updateScreens:)
                       name:NSApplicationDidChangeScreenParametersNotification
                     object:NSApp];
    

    L130:

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多