@class AVPlayerLayer 的预期不合格 ID
Expected unqualified-id for @class AVPlayerLayer
在我的 qt 应用程序中,我在头文件 (frame.h
) 中声明了一个 @class AVPlayerLayer
,它在源文件 (frame.mm
) 中包含 <AVFoundation/AVFoundation.h>
.
当我尝试使用 qt creator 编译它时,出现以下错误:
Expected unqualified-id for @class AVPlayerLayer
unknown type name 'AVPlayerLayer'
我正在尝试转发 class 声明,因为我希望我的头文件知道期望 AVPlayerLayer
包含在我的 .mm
文件中 AVFoundation
,我这样做的原因是因为头文件不能包含 Objective-C
代码。
frame.h:
#include <QObject>
#include <QQuickItem>
typedef struct __CVBuffer *CVBufferRef;
typedef CVBufferRef CVImageBufferRef;
typedef CVImageBufferRef CVOpenGLESTextureRef;
typedef CVOpenGLESTextureRef CVOGLTextureRef;
@class AVPlayerLayer;
//-----------------
class FrameRenderer : public QObject
{
Q_OBJECT
private:
CVOGLTextureRef renderLayerToTexture(AVPlayerLayer *layer);
public:
FrameRenderer(QAbstractVideoSurface *surface, QObject *parent = 0);
};
frame.mm
#include "frame.h"
#import <AVFoundation/AVFoundation.h>
FrameRenderer::FrameRenderer(QObject *parent)
: QObject(parent)
{
}
CVOGLTextureRef FrameRenderer::renderLayerToTexture(AVPlayerLayer *layer)
{
size_t dummyWidth = 0, dummyHeight = 0;
return createCacheTextureFromLayer(layer, dummyWidth, dummyHeight);
}
根据http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++
您可以转发声明您的 objective c class:
#ifdef __OBJC__
@class AVPlayerLayer;
#else
typedef struct objc_object AVPlayerLayer;
#endif
在我的 qt 应用程序中,我在头文件 (frame.h
) 中声明了一个 @class AVPlayerLayer
,它在源文件 (frame.mm
) 中包含 <AVFoundation/AVFoundation.h>
.
当我尝试使用 qt creator 编译它时,出现以下错误:
Expected unqualified-id for @class AVPlayerLayer
unknown type name 'AVPlayerLayer'
我正在尝试转发 class 声明,因为我希望我的头文件知道期望 AVPlayerLayer
包含在我的 .mm
文件中 AVFoundation
,我这样做的原因是因为头文件不能包含 Objective-C
代码。
frame.h:
#include <QObject>
#include <QQuickItem>
typedef struct __CVBuffer *CVBufferRef;
typedef CVBufferRef CVImageBufferRef;
typedef CVImageBufferRef CVOpenGLESTextureRef;
typedef CVOpenGLESTextureRef CVOGLTextureRef;
@class AVPlayerLayer;
//-----------------
class FrameRenderer : public QObject
{
Q_OBJECT
private:
CVOGLTextureRef renderLayerToTexture(AVPlayerLayer *layer);
public:
FrameRenderer(QAbstractVideoSurface *surface, QObject *parent = 0);
};
frame.mm
#include "frame.h"
#import <AVFoundation/AVFoundation.h>
FrameRenderer::FrameRenderer(QObject *parent)
: QObject(parent)
{
}
CVOGLTextureRef FrameRenderer::renderLayerToTexture(AVPlayerLayer *layer)
{
size_t dummyWidth = 0, dummyHeight = 0;
return createCacheTextureFromLayer(layer, dummyWidth, dummyHeight);
}
根据http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++
您可以转发声明您的 objective c class:
#ifdef __OBJC__
@class AVPlayerLayer;
#else
typedef struct objc_object AVPlayerLayer;
#endif