【发布时间】:2014-05-01 08:05:56
【问题描述】:
我正在尝试在我的 Mac 应用程序上运行本机 object-c 代码。
我的代码如下:
MainWindow.h:
#ifdef Q_OS_MAC
#include <Carbon/Carbon.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <mach/mach_port.h>
#include <mach/mach_interface.h>
#include <mach/mach_init.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
#endif
MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
#ifdef Q_OS_MAC
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveSleepNote:)
name: NSWorkspaceWillSleepNotification object: NULL];
#endif
}
#ifdef Q_OS_MAC
- (void) receiveSleepNote: (NSNotification*) note
{
NSLog(@"receiveSleepNote: %@", [note name]);
}
#endif
但是我得到的错误似乎是 QT 不理解代码结构:
application.cpp:错误:预期的外部声明 - (void) receiveSleepNote: (NSNotification*) note ^
【问题讨论】:
-
有一个相当 good reference 用于混合 Obj-C 和 C++。
标签: objective-c qt