Search code examples
macosqtcmakensimageqtmacextras

QtMac::toNSImage Undefined symbols for architecture x86_64


I am trying to use notifications in a Qt application on Mac.

Here is part of my class

#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];
}

Here is the error message I get:

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

Any idea what's going on?


Solution

  • Finally found it.

    In CMakeLists.txt, I had

    FIND_PACKAGE(Qt5MacExtras)

    but was missing

    TARGET_LINK_LIBRARIES(qgis_native Qt5::MacExtras)