Pregunta

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.

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.

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.

Thanks in advance.

Edit :

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

  • Expand the tree to C/C++ General / Paths and Symbols
  • Change the Configuration in the Paths and Symbols frame to [All configurations]
  • Click the Includes tag and select GNU C in the Languages list (or do this for every language).
  • Click Add... and type ${QNX_TARGET}/usr/include/qt4 and press OK
  • Click Add... and type ${QNX_TARGET}/usr/include/qt4/QtCore and press OK

  • 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.

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

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.

¿Fue útil?

Solución

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.

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.

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.

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…

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top