QtMac :: toNSImage体系结构x86_64的未定义符号

时间:2018-08-07 20:35:48

标签: macos qt cmake nsimage qtmacextras

我正在尝试在Mac上的Qt应用程序中使用通知。

这是我班的一部分

#include <Cocoa/Cocoa.h>
#include <QtMacExtras/QtMac>
#include <objc/objc.h>

#include <QString>
#include <QPixmap>

void QgsMacNative::showDesktopNotification( const QString &summary,
    const QString &body,
    const QgsNative::NotificationSettings &settings )
{
  NSUserNotification *notification = [[NSUserNotification alloc] init];
  notification.title = summary.toNSString();
  notification.informativeText = body.toNSString();
  notification.soundName = NSUserNotificationDefaultSoundName;   //Will play a default sound
  notification.contentImage = QtMac::toNSImage( QPixmap::fromImage( settings.image ) );
  [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
  [notification autorelease];
}

这是我收到的错误消息:

Undefined symbols for architecture x86_64:
  "QtMac::toNSImage(QPixmap const&)", referenced from:
    QgsMacNative::showDesktopNotification(QString const&, QString const&, QgsNative::NotificationSettings const&) in qgsmacnative.mm.o
ld: symbol(s) not found for architecture x86_64

知道发生了什么吗?

2 个答案:

答案 0 :(得分:0)

最后找到了。

我在CMakeLists.txt中

FIND_PACKAGE(Qt5MacExtras)

但丢失了

TARGET_LINK_LIBRARIES(qgis_native Qt5::MacExtras)

答案 1 :(得分:0)

就我而言,我在QT +=文件中缺少.pro个条目。

示例:

QT       += widgets core gui

应该是:

QT       += widgets core macextras gui