如何在基于BB10 Cocos2D的应用程序中导入和使用QObject [英] How to import and use QObject in a BB10 Cocos2D based app

查看:129
本文介绍了如何在基于BB10 Cocos2D的应用程序中导入和使用QObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Cocos2dx随附的BBTemplateProject示例为BB10平台构建Cocos2d-x游戏.我是C ++编程的新手,当前的游戏是Iv从事一段时间的Java项目的移植.为了保存游戏数据(分数,某些设置等),我打算使用BB10提供的QtSQl库. 我已经在示例Cascades应用程序中成功运行了一些示例Qtsql代码,并且工作正常. 但是,将相同的代码集成到我的Cocos2dx BB10项目中只是行不通的. 我使用momentics IDE,并向项目添加了qt4,QtCore,QtDeclarative,路径/符号,但仍然收到以下错误

I am currently working on building a Cocos2d-x game for the BB10 platform using the BBTemplateProject sample provided with Cocos2dx. I am new to C++ programming, and the current game is a port of a java project Iv been working on for a while. In order to save game data (scores, some settings etc), I intend to use the QtSQl Library which BB10 provides. I have successfully run some sample Qtsql code in a sample Cascades application and it works fine. However, integrating the same code into my Cocos2dx BB10 project just doesnt work . I use the momentics IDE and have added the qt4, QtCore, QtDeclarative, paths/symbols to the project but still recieve the following errors

undefined reference to `QObject::QObject(QObject*)'
undefined reference to `vtable 
undefined reference to `QSqlDatabase::defaultConnection'
.. and a bunch of other Q- related object errors.

在此处阅读Qobject后,请 http://developer.blackberry.com/cascades/reference/moc.html 我怀疑MOC编译器不适合引用或类似的问题.此外,由于将相同的代码集成到Momentics IDE中的自动生成的级联项目中时效果很好,因此我相信这是某种moc编译器问题.鉴于我刚接触C ++开发,我仍然无法弄清楚如何向Momentics IDE中添加适当的qmake文件规则以识别Qobjects.这方面需要帮助.

After reading up on Qobject here http://developer.blackberry.com/cascades/reference/moc.html I suspect that the MOC compiler is not appropriating referenced or a similar issue. Also, given the same code works well when integrated in an auto generated cascades project in the Momentics IDE, I am led to believe it is some sort of moc compiler issue. Given that I am quite new to C++ development, I still havent been able to figure out how to add the appropriate qmake file rules to the Momentics IDE in order to recognise Qobjects . Help is needed in this area.

对于经验丰富的c ++开发人员如何进行此操作,或者在cocos2dx blackberry 10项目中存储数据的更好方法,我们将绝对表示赞赏.

Will definitely appreciate any pointers on how to go about this from experienced c++ devs or better ways to store data within cocos2dx blackberry 10 projects.

谢谢.

在这里,到目前为止,我在尝试使用QtSql进行数据库交互方面的进展. QtSQl需要包含上面QObject的QtCore.到目前为止,我还无法成功集成QtCore库.

Here's , my progress thus far in trying to use QtSql for database interaction. QtSQl requires QtCore which contains QObject above. Thus far I have been unable to successfully integrate QtCore library.

我已经完成了以下工作.

I have done the following.

  • 使用以下过程

  • Added the /usr/include/qt4 and /usr/include/QtCore and /usr/include/QtSql to my include list using the following procedure

在项目资源管理器"中右键单击您的项目,然后选择属性"

Right click over your project in Project Explorer and choose Properties

单击添加...",然后键入$ {QNX_TARGET}/usr/include/qt4/QtCore并按确定"

Click Add... and type ${QNX_TARGET}/usr/include/qt4/QtCore and press OK

使用Momentics IDE添加库函数将QtCore和QtSql都添加到项目中.右键单击->配置->添加库和标准BlackBerry Platform库.该库已成功添加.

Used the Momentics IDE add library function to add both QtCore and QtSql to the project. RightClick->configure->add Library and Standard BlackBerry Platform Library. The library gets added successfully.

我基本上遵循了这篇相关文章中详细介绍的步骤在Blackberry中添加QtCore库10 sdk .但是现在得到这个错误.

I basically followed the steps detailed in this related post Adding QtCore Library in blackberry 10 sdk . But now get this error.

\win32\x86\usr\bin\ntoarm-ld: cannot find -lQtCore

那篇文章中的OP提到解决一些链接器问题",但是没有提及如何解决.我还尝试过修改bar-descriptor.xml文件,添加以下几行

The OP in that post mentions solving "some linker problems" but fails to mention how. I have also tried modifying the bar-descriptor.xml file adding the following lines

  <env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>
<asset path="${QNX_TARGET}\${CPUVARDIR}usr\lib\qt4\lib\libQtCore.so" type="Qnx/Elf">lib/libQtCore.so.4</asset>

错误仍然存​​在. 如何解决此链接器"或找不到库的错误?非常感谢.

Error still remains. How do I solve this "linker" or library-no-found error ? Many Thanks.

推荐答案

首先,如果您打算在BlackBerry 10和我想使用的Java上同时使用相同的应用程序,那么您将尝试使用Java比Qt小一些的东西,例如 SQLite库,以使其尽可能简单地在两者之间移植平台.但是显然您可以在BB10上使用QtSQL并在Android上使用其他功能,您只需要编写更多代码即可.

First, if you plan to use the same application on both BlackBerry 10 and, I guess, Android as you are coming from Java, I'd try to use something smaller than Qt, like SQLite library, to keep it as simple as possible to port between the two platforms. But you can obviously use QtSQL on BB10 and something else in Android, you'll just have more code to write.

其次,关于您的问题:对QObject::QObject(QObject*)的未定义引用意味着您正在使用此符号(QObject构造函数,您可能会调用它,因为您的某个类继承自QObject),但没有任何事情提供它.您可能已经在编译器找到QtCore时将其添加到了include路径中,但没有链接器:您需要指定要与QtCore.so(或者可能是QtCore4.so)链接的应用程序,但我没有SDK现在检查确切名称).您将找到有关如何执行此操作的所有信息

Second, regarding your issue: the undefined reference to QObject::QObject(QObject*) means that you are using this symbol (the QObject constructor, which you are probably calling because one of you class inherits from QObject), but nothing is providing it. You have probably added QtCore to your include path as the compiler found it, but not the linker: you need to specify that you want your application to be linked with QtCore.so (or maybe QtCore4.so, I don't have the SDK right now to check the exact name). You'll find everything you need on how to do this here.

关于moc:moc代表Meta Object Compiler.它基本上解析您的标头,在类上查找元数据:主要是属性,信号和插槽.更具体地说,所有需要Q_OBJECT宏的内容.如果您不使用这些功能,则无需运行moc.

About moc: moc stands for Meta Object Compiler. It basically parses your headers, looking for metadata on your classes: mainly properties, signals and slots. More specifically, everything that requires the Q_OBJECT macro. If you don't use theses functionalities, you don't need to run moc.

如果必须运行它(因为使用了一些元对象功能):您有两个选择.选项一:使用QMake编译您的项目.为此,您必须从头开始将您的项目重新创建为Qt项目(也许与Momentics上的Cascades项目没有区别,但这只是删除要链接的库的问题,没什么大不了的).选项二:添加自定义规则以在需要它的标头上运行moc.它将生成一些需要包含在项目中的moc_yourclass.cpp文件.我不知道如何在Momentics上添加自定义步骤,但我认为应该可行…

If you have to run it (because you use some meta object functionalities): you have two options. Option one: use QMake to compile your project. You'll have to recreate your project from scratch as a Qt project (maybe not differentiated of Cascades projects on Momentics, however it's just a matter of removing libraries you're linking to, not a big deal) to do this. Option two: add custom rules to run moc on headers needing it. It will generates some moc_yourclass.cpp files that you'll need to include in your project. I don't know how to do add a custom step on Momentics, but I think it should be doable…

这篇关于如何在基于BB10 Cocos2D的应用程序中导入和使用QObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆