Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
ryan_robinson
Posts: 60
Registered: ‎03-07-2011
My Carrier: Telus
Accepted Solution

qmlRegisterType Problem

I'm having trouble registering a type to QML. The first time I did it with the DataModel type PrayerModel I got it to work. However, I'm getting errors with the PrayerBBMManager now. It's based on the BucketList sample but I've massively simplified the entire BBM functionality.

 

The actual errors say:

Description	Resource	Path	Location	Type
undefined reference to `prayerbbm::PrayerBBMManager::~PrayerBBMManager()'	PrayerJournal		line 86, external location: f:\bbndk\target_10_0_9_2318\qnx6\usr\include\qt4\QtDeclarative\qdeclarativeprivate.h	C/C++ Problem

Description	Resource	Path	Location	Type
undefined reference to `prayerbbm::PrayerBBMManager::PrayerBBMManager(QObject*)'	PrayerJournal		line 82, external location: f:\bbndk\target_10_0_9_2318\qnx6\usr\include\qt4\QtDeclarative\qdeclarativeprivate.h	C/C++ Problem

Description	Resource	Path	Location	Type
undefined reference to `prayerbbm::PrayerBBMManager::staticMetaObject'	PrayerJournal		line 163, external location: f:\bbndk\target_10_0_9_2318\qnx6\usr\include\qt4\QtDeclarative\qdeclarative.h	C/C++ Problem

Description	Resource	Path	Location	Type
undefined reference to `prayerbbm::PrayerBBMManager::staticMetaObject'	PrayerJournal		line 189, external location: f:\bbndk\target_10_0_9_2318\qnx6\usr\include\qt4\QtDeclarative\qdeclarative.h	C/C++ Problem

 

Here's my PrayerJournal.cpp file:

#include "PrayerJournal.h"
#include "prayermodel.h"
#include "prayerbbm/prayerbbmmanager.h"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

using namespace bb::cascades;
using namespace prayerbbm;

PrayerJournal::PrayerJournal(bb::cascades::Application *app)
: QObject(app)
{
	qDebug() << "starting PrayerJournal app constructor ";
	QCoreApplication::setOrganizationName("Alliteration Applications");
	QCoreApplication::setOrganizationDomain("http://alliterationapplications.com");
	QCoreApplication::setApplicationName("Prayer Journal");

  qmlRegisterType<PrayerModel>("com.prayerjournal.prayerdata", 1, 0, "PrayerModel");
  qmlRegisterType<PrayerBBMManager>("com.prayerjournal.prayerbbm", 1, 0, "PrayerBBMManager");
  qDebug() << "Registered PrayerModel and PrayerBBM types for QML";

  // Create a QMLDocument and load it, using build patterns.
  QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

  if (!qml->hasErrors()) {
	  qDebug() << "QML is error-free! Celebrate!";
  }
  if (qml->hasErrors()) {
	  qDebug() << "QML has errors";
  }

  //qml->setContextProperty("registrationHandler", registrationHandler);
  AbstractPane *appPage = qml->createRootObject<AbstractPane>();
  Application::instance()->setScene(appPage);

  qDebug() << "Created and initialized main.qml";
}

 Through steadily commenting out everything that references BBM from the qml files and then working backwards into this file I can pinpoint the problem happening with the qmlRegisterType statement.

 

Here's from the prayerbbmmanager.h:

namespace prayerbbm
{
    /**
     * PrayerBBMManager Description:
     *
     * This manager takes care of registering the application with BBM
     */
    class PrayerBBMManager: public QObject
    {
    Q_OBJECT

    public:
        PrayerBBMManager(QObject *parent = 0);

        virtual ~PrayerBBMManager();

 And the prayerbbmmanager.cpp:

namespace prayerbbm
{
    PrayerBBMManager::PrayerBBMManager(QObject *parent) :
            QObject(parent)
    {
    	 m_uuid = QString::fromUtf8("d8484b8d-bed5-4cde-8c11-462c6a04bc35");

    	 if (mSettings.value("connectToBBM").isNull()) {
    	    mSettings.setValue("connectToBBM", QVariant(false));
    	 }
    }

    PrayerBBMManager::~PrayerBBMManager()
    {
    }

 Any help would be appreciated.

Please use plain text.
Developer
strobejb
Posts: 246
Registered: ‎10-15-2012
My Carrier: Orange

Re: qmlRegisterType Problem

Looks like a linker problem? its not finding your class, which implies the member functions (constructor, destructor etc) are not being linked correctly.

Try cleaning your project and then rebuilding (Project -> Clean)
Please use plain text.
Regular Contributor
ryan_robinson
Posts: 60
Registered: ‎03-07-2011
My Carrier: Telus

Re: qmlRegisterType Problem

I've done the clean and rebuild but it didn't help. Am I missing something obvious?

Please use plain text.
Regular Contributor
pskarton
Posts: 70
Registered: ‎09-06-2012
My Carrier: Bell Mobility

Re: qmlRegisterType Problem

I have something like this

 

In QML

  import CustomPrayerModel 1.0

 

In C++

qmlRegisterType<PrayerModel>("CustomPrayerModel", 1, 0, "PrayerModel");

 where PrayerModel is my class

Please use plain text.
Regular Contributor
ryan_robinson
Posts: 60
Registered: ‎03-07-2011
My Carrier: Telus

Re: qmlRegisterType Problem

That's the format which I have, and it works for PrayerModel so I'm not sure why it isn't working for PrayerBBMManager.

Please use plain text.
Developer
strobejb
Posts: 246
Registered: ‎10-15-2012
My Carrier: Orange

Re: qmlRegisterType Problem

still seems like a linker problem to me. 

 

What directory is your .cpp and .hpp file in? 

What does your PRO file look like?

Please use plain text.
Developer
Zmey
Posts: 1,494
Registered: ‎12-18-2012

Re: qmlRegisterType Problem

[ Edited ]

Seems like constructor implementation is outside of the namespace.

Try adding "namespace prayerbbm { ... }" to .cpp file as well:

namespace prayerbbm
{

PrayerJournal::PrayerJournal(bb::cascades::Application *app)
: QObject(app)
..........

}

 

"using namespace" doesn't automatically put all declared functions into the namespace.

 

Sorry, it's already there. :Sweatdrop:

 

Is <QObject> included in prayerbbmmanager.h?

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
strobejb
Posts: 246
Registered: ‎10-15-2012
My Carrier: Orange

Re: qmlRegisterType Problem

[ Edited ]

Yes that could be it -

My money is also on the PrayerBBMManager sources not being MOC'd because they have been moved into a directory that isn't referenced in the project's .pro file

Please use plain text.
Regular Contributor
ryan_robinson
Posts: 60
Registered: ‎03-07-2011
My Carrier: Telus

Re: qmlRegisterType Problem

Changed this to the .pro file

INCLUDEPATH += ../src ../src/prayerbbm
SOURCES += ../src/*.cpp ../src/prayerbbm/*.cpp
HEADERS += ../src/*.hpp ../src/*.h ../src/prayerbbm/*h ../src/prayerbbm/*.hpp

 The previous error is now gone. There are a bunch in the PrayerBBMManager instead but the original error is gone so I believe you have solved it for me. Thank you.

Please use plain text.