【Qt】添加新文件后编译报错:VideoRender::qt_metacall(QMetaObject::Call, int, void**)“, referenced from

18 篇文章 0 订阅
9 篇文章 0 订阅

在Qt项目中,添加新的c++文件后,使用该类时,编译报错。

网上对于这种报错,说法各异。

其实,原因很简单。

就是需要在CMakeLists.txt中,添加头文件和实现文件的配置项即可。

【编译报错】:

"VideoRender::qt_metacall(QMetaObject::Call, int, void**)", referenced from:

      vtable for QQmlPrivate::QQmlElement<VideoRender> in main.cpp.o

  "VideoRender::qt_metacast(char const*)", referenced from:

      vtable for QQmlPrivate::QQmlElement<VideoRender> in main.cpp.o

  "VideoRender::staticMetaObject", referenced from:

      int qmlRegisterType<VideoRender>(char const*, int, int, char const*) in main.cpp.o

      QtPrivate::MetaObjectForType<VideoRender*, void>::value() in main.cpp.o

      QMetaTypeIdQObject<VideoRender*, 8>::qt_metatype_id() in main.cpp.o

  "VideoRender::VideoRender(QObject*)", referenced from:

      QQmlPrivate::QQmlElement<VideoRender>::QQmlElement() in main.cpp.o

  "VideoRender::~VideoRender()", referenced from:

      QQmlPrivate::QQmlElement<VideoRender>::~QQmlElement() in main.cpp.o

  "VideoRender::metaObject() const", referenced from:

      vtable for QQmlPrivate::QQmlElement<VideoRender> in main.cpp.o

  "typeinfo for VideoRender", referenced from:

      typeinfo for QQmlPrivate::QQmlElement<VideoRender> in main.cpp.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [FrtcMeeting.app/Contents/MacOS/FrtcMeeting] Error 1

make[1]: *** [CMakeFiles/FrtcMeeting.dir/all] Error 2

make: *** [all] Error 2

【根源】:

添加新文件后,没有在配置文件中添加新文件的路径,导致编译报错。

【解决方法】:

在CMakeLists.txt中,添加头文件和实现文件的路径即可。

# 1.Add header file include directories.

include_directories(

./Video/VideoRender/

)

# 2. Get all .cpp/.c/.cc files.

aux_source_directory(/Video/VideoRender/. VIDEO_RENDER_DIR_SRC)

# 3.Target

add_executable(FrtcMeeting

MACOSX_BUNDLE

$(VIDEO_RENDER_DIR_SRC)

...

main.cpp

qml.qrc

)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值