0

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.

Community
  • 1
  • 1
Vykthur D .
  • 351
  • 2
  • 7

1 Answers1

1

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…

Marc Plano-Lesay
  • 6,808
  • 10
  • 44
  • 75
  • Hi Kernald, Thanks for the detailed reply, I'll definitely check out the link you provided on linking to QtCore.so etc. Hopefully it solves my undefined reference issue. However you raise an important option I'd like to double down on - using SQLite library. How do I use the SQLite library on bb10 ? I earlier assumed that the only way to use sqlite on BB10 was to use QtSQL. This ? https://developer.blackberry.com/cascades/reference/bb__data__sqldataaccess.html ? P.S I am not using same application on both Android and BB10. Android version was written in cocos2d for android, a java port . – Vykthur D . Jul 27 '13 at 01:31
  • 1
    Well, I was thinking about this: http://www.sqlite.org/capi3ref.html which is the "official" SQLite library (I also added the link in my answer to avoid confusion). Other ones are mainly wrappers around it, or recode the same functionalities with more complete API/abstraction. It has the advantage of being fully cross-platform. However, if you plan to use this code on BB10 only, SqlDataAccess or QtSql would be a better choice I think. At least, easier to use. I didn't know about SqlDataAccess. I'll guess it will be up to you to compare it to QtSql and choose what you prefer. – Marc Plano-Lesay Jul 27 '13 at 01:41
  • Your link sounds like a good option. However, I imagine integrating it to BB10 might be another tug of war. From the samples Iv seen using SqlDataAcess works in conjunciton with QtSql as opposed to working independently (http://developer.blackberry.com/cascades/reference/bb__data__sqldataaccess.html) . All being said, there are several valuable Q- functions (e.g QString) that come along with successfully importing/integrating the QtCore/Qtsql libraries, that motivate the choice of going with QtSql. – Vykthur D . Jul 29 '13 at 11:22
  • Targeting BB10 only, ``QtSql`` and/or ``SqlDataAccess`` is probably the way to go. However, for reference: the SQLite library is only a single C file, without any dependency. It's pretty straightforward to include in a project ;-) – Marc Plano-Lesay Jul 29 '13 at 14:54