相关疑难解决方法(0)

QT运行Objective-C代码

我正在尝试在Mac应用程序上运行本机对象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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

但是正在收到似乎QT无法理解代码结构的错误:

application.cpp:错误:预期的外部声明-(void)receiveSleepNote:(NSNotification *)注意^

qt objective-c

5
推荐指数
1
解决办法
3276
查看次数

标签 统计

objective-c ×1

qt ×1