Blackberry 在无头应用程序的 QML 中使用 C++ 类:对 `bb::device::VibrationController::staticMetaObject' 的未定义引用

Blackberry using C++ classes in QML in headless app: undefined reference to `bb::device::VibrationController::staticMetaObject'

我在 BB 上工作了几个星期,遇到了很多麻烦。其中一些已解决,有些并非没有论坛的支持。 现在我有一个大麻烦,我无法通过谷歌搜索找到答案。 如果有人能提供帮助,我将不胜感激。

这是一个简单的案例,但对我来说却是个大问题:

  1. 使用 Momentics 创建无头应用程序。将生成两个项目 HeadlessApp 和 HeadlessAppService。 不用修改,这段代码运行很好。

  2. 我按照this link在HeadlessAppService中使用VibrationController 将以下代码添加到 HeadlessAppService

  3. 的 main.cpp

#include <bb/device/VibrationController>

using namespace bb::device;

然后添加 qmlRegisterType 如下

Q_DECL_EXPORT int main(int argc, char **argv)
{

   Application app(argc, argv);

   qmlRegisterType<VibrationController>("bb.vibrationController", 1, 0, "VibrationController");
   ApplicationUI appui;
   return Application::exec();
}
  1. 为了确认这个新代码,我只需右键单击项目,然后 select 构建项目。 砰!!!我有很多我无法理解的错误。 (红线是错误)

08:44:30 **** Incremental Build of configuration Device-Debug for project headlessTest ****
make -j4 Device-Debug 
make -C .//translations -f Makefile update
make[1]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
C:/bbndk/host_10_3_1_12/win32/x86/usr/bin/lupdate headlessTest.pro
Updating 'headlessTest.ts'...
    Found 2 source text(s) (0 new and 2 already existing)
make[1]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
make -C .//translations -f Makefile release
make[1]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
C:/bbndk/host_10_3_1_12/win32/x86/usr/bin/lrelease headlessTest.pro
Updating 'D:/BB-dev/momentics-workspace/headlessTest/translations/headlessTest.qm'...
    Generated 0 translation(s) (0 finished and 0 unfinished)
    Ignored 2 untranslated source text(s)
make[1]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/translations'
make -C ./arm -f Makefile debug
make[1]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
make -f Makefile.Debug
make[2]: Entering directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
qcc -Vgcc_ntoarmv7le -lang-c++ -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/lib -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/qt4/lib -Wl,-rpath-link,C:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/qt4/lib -o o.le-v7-g/headlessTest o.le-v7-g/.obj/applicationui.o o.le-v7-g/.obj/main.o o.le-v7-g/.obj/moc_applicationui.o    -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/bb1 -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/lib -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib -LC:/bbndk/target_10_3_1_995/qnx6/armle-v7/usr/lib/qt4/lib -LC:/bbndk/target_10_3_1_995/qnx6//usr/lib/qt4/lib -lbb -lbbsystem -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps 
o.le-v7-g/.obj/main.o: In function `int qmlRegisterType<bb::device::VibrationController>(char const*, int, int, char const*)':
**c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarative.h:191: undefined reference to `bb::device::VibrationController::staticMetaObject'
o.le-v7-g/.obj/main.o: In function `QDeclarativeElement':
**c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:87: undefined reference to `bb::device::VibrationController::VibrationController(QObject*)'
o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0x8): undefined reference to `bb::device::VibrationController::metaObject() const'
o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0xc): undefined reference to `bb::device::VibrationController::qt_metacast(char const*)'
o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTVN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0x10): undefined reference to `bb::device::VibrationController::qt_metacall(QMetaObject::Call, int, void**)'
o.le-v7-g/.obj/main.o:(.data.rel.ro._ZTIN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE[_ZTIN19QDeclarativePrivate19QDeclarativeElementIN2bb6device19VibrationControllerEEE]+0x8): undefined reference to `typeinfo for bb::device::VibrationController'
o.le-v7-g/.obj/main.o: In function `~QDeclarativeElement':
**c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:91: undefined reference to `bb::device::VibrationController::~VibrationController()'
**c:/bbndk/target_10_3_1_995/qnx6/usr/include/qt4/QtDeclarative/qdeclarativeprivate.h:91: undefined reference to `bb::device::VibrationController::~VibrationController()'cc: C:/bbndk/host_10_3_1_12/win32/x86/usr/bin/ntoarm-ld caught signal 1
**    Makefile.Debug:103: recipe for target 'o.le-v7-g/headlessTest' failed
make[2]: *** [o.le-v7-g/headlessTest] Error 1make[2]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
make[1]: *** [debug] Error 2
Makefile:50: recipe for target 'debug' failed
make: *** [Device-Debug] Error 2make[1]: Leaving directory 'D:/BB-dev/momentics-workspace/headlessTest/arm'
mk/cs-base.mk:31: recipe for target 'Device-Debug' failed
08:44:31 Build Finished (took 1s.47ms)

错误行标有**(2 星)。 我要放弃了!!! 为什么添加简单的代码会产生问题?请帮我! 非常感谢!

我找到原因了。我忘了将 LIBS += -lbbdevice 添加到 pro 文件中。