Qt + cocoa:架构x86_64的未定义符号

时间:2013-03-26 11:37:12

标签: macos cocoa qt

我在Qt中组合了可可代码,遗憾的是发现了一个未找到符号的错误。 我正在使用MAC OSX 10.8.2和Qt Creator来构建我的代码。

appcontroller.h

#ifndef APPCONTROLLER_H
#define APPCONTROLLER_H

// Import the Cocoa and ImageCaptureCore headers
#include <Cocoa/Cocoa.h>
#include <ImageCaptureCore/ImageCaptureCore.h>

// Create a public interface for the controller
@interface appController : NSObject

// Create delegates for the device browser and camera device classes.
<ICDeviceBrowserDelegate, ICCameraDeviceDelegate> {

// Create an instance variable for the device browser
// and an array for the cameras the browser finds
ICDeviceBrowser * mDeviceBrowser;
NSMutableArray * mCameras;

// Define Interface Builder outlets for two
// array controllers -- one for cameras,
// one for the chosen camera's files
IBOutlet NSArrayController * mCamerasController;
IBOutlet NSArrayController * mMediaFilesController;

// Define IB outlets for the tableviews used to
// display the cameras and the chosen camera's contents
IBOutlet NSTableView * mCameraContentTableView;
IBOutlet NSTableView * mCamerasTableView;
}

// Cameras are properties of the device browser stored in an array
@property(retain) NSMutableArray* cameras;

// Create a boolean to indicate whether the camera has images to download
@property(readonly) BOOL canDownload;
@end


#endif // APPCONTROLLER_H

要复制到剪贴板,请将视图切换为纯文本模式

appcontroller.mm

#include "appcontroller.h"

// The camera device returns core graphics image refs,
// convert them to NSImages for table view
@interface NSImageFromCGImageRef: NSValueTransformer {}
@end
@implementation NSImageFromCGImageRef
+ (Class)transformedValueClass { return [NSImage class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
- (id)transformedValue:(id)item
{
if ( item )
return [[[NSImage alloc] initWithCGImage:(CGImageRef)item size:NSZeroSize] autorelease];
else
return nil;
} @end
@implementation appController

// synthesize the getters and setters for camera properties
@synthesize cameras = mCameras;

// Main task -- on launch
- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
mCameras = [[NSMutableArray alloc] initWithCapacity:0];

// Get an instance of ICDeviceBrowser
mDeviceBrowser = [[ICDeviceBrowser alloc] init];
// Assign a delegate
mDeviceBrowser.delegate = self;
// Look for cameras in all available locations
mDeviceBrowser.browsedDeviceTypeMask = mDeviceBrowser.browsedDeviceTypeMask
| ICDeviceTypeMaskCamera
| ICDeviceLocationTypeMaskLocal
| ICDeviceLocationTypeMaskShared
| ICDeviceLocationTypeMaskBonjour
| ICDeviceLocationTypeMaskBluetooth
| ICDeviceLocationTypeMaskRemote;
// Start browsing for cameras
[mDeviceBrowser start];

}

// Stop browser and release it when done
- (void)applicationWillTerminate:(NSNotification*)notification {
mDeviceBrowser.delegate = NULL;
[mDeviceBrowser stop];
[mDeviceBrowser release];
[mCameras release];
}

// Method delegates for device added and removed
//
// Device browser maintains list of cameras as key-value pairs, so delegate
// must call willChangeValueForKey to modify list
- (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice moreComing:(BOOL)moreComing
{
if ( addedDevice.type & ICDeviceTypeCamera )
{
addedDevice.delegate = self;

// implement manual observer notification for the cameras property
[self willChangeValueForKey:@"cameras"];
[mCameras addObject:addedDevice];
[self didChangeValueForKey:@"cameras"];
}
}


- (void)deviceBrowser:(ICDeviceBrowser*)browser didRemoveDevice:(ICDevice*)device moreGoing:(BOOL)moreGoing
{
device.delegate = NULL;

// implement manual observer notification for the cameras property
[self willChangeValueForKey:@"cameras"];
[mCameras removeObject:device];
[self didChangeValueForKey:@"cameras"];
}

- (void)didRemoveDevice:(ICDevice*)removedDevice
{
[mCamerasController removeObject:removedDevice];
}

// Check to see if the camera has image files to download
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
{
if ( [keyPath isEqualToString:@"selectedObjects"] && (object == mMediaFilesController) )
{
[self willChangeValueForKey:@"canDownload"];
[self didChangeValueForKey:@"canDownload"];
}
}

- (BOOL)canDownload
{
if ( [[mMediaFilesController selectedObjects] count] )
return YES;
else
return NO;
}

// Download images
// (Add a download button in interface builder -- use boolean to enable button)
- (void)downloadFiles:(NSArray*)files
{
NSDictionary* options = [NSDictionary dictionaryWithObject:[NSURL fileURLWithPath:[@"~/Pictures" stringByExpandingTildeInPath]] forKey:ICDownloadsDirectoryURL];

for ( ICCameraFile* f in files )
{
[f.device requestDownloadFile:f options:options downloadDelegate:self didDownloadSelector:@selector(didDownloadFile:error:options:contextInfo:) contextInfo:NULL];
}
}

// Done downloading -- log results to console for debugging
- (void)didDownloadFile:(ICCameraFile*)file error:(NSError*)error options:(NSDictionary*)options contextInfo:(void*)contextInfo
{
NSLog( @"didDownloadFile called with:\n" );
NSLog( @" file: %@\n", file );
NSLog( @" error: %@\n", error );
NSLog( @" options: %@\n", options );
NSLog( @" contextInfo: %p\n", contextInfo );
}
@end

要复制到剪贴板,请将视图切换为纯文本模式

和 ObjectiveC-Integrate.pro

QT += core gui multimedia

TARGET = ObjectiveC-Integrate
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui

CONFIG -= app_bundle
CONFIG += x86_64
CONFIG -= i386
LIBS += -lssl -lcrypto
LIBS += -framework AppKit

OBJECTIVE_HEADERS += \
appcontroller.h

OBJECTIVE_SOURCES += \
appcontroller.mm

要复制到剪贴板,请将视图切换为纯文本模式 经过大量搜索谷歌和审查其他帖子后,我无法在我的机器上生成我的代码。 当我在main.cpp中包含上面的COCOA标题时,会出现数千个错误(@ stray)..

1 个答案:

答案 0 :(得分:0)

您不能在您的C ++文件(main.cpp)中包含Objective C标头(appcontroller.h)。 C ++不了解Objective C。

您需要使用此答案中给出的方法之一:Calling Objective-C method from C++ method?