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
Contributor
danjohnson
Posts: 18
Registered: ‎10-09-2012
My Device: Blackberry 10 Dev Alpha Simulator
My Carrier: Verizon

Can't Build Sample C++/Cascades Project - make errors

[ Edited ]

Hello,

 

I am trying to update an app I was working on over the summer, with a previous SDK release, which was working fine, and had several c++ classes and methods interacting with the cascades UI.  It was working fine with no problems.

 

After installing the new "Gold" SDK and simulator, I am unable to build it.  

 

I realized after some trial and error that the errors appear as soon as any C++ class is exposed to QML, or really, as soon as I extend QObject in a class.

 

To narrow down the issue, I created a new, blank C++/Cascades project, and created a class similar to the examples in the C++/Cascades Integration doc and still got the errors right away.

 

Here's the errors:

 

make: *** [Simulator-Debug] Error 2

make[1]: *** [debug] Error 2

make[2]: *** [o-g./.obj/MyClass.o] Error 1

undefined reference to 'MyClass::valueChanged(int)'

undefined reference to 'MyClass::valueChanged(int)'

undefined reference to 'vtable for MyClass'

undefined reference to 'vtable for MyClass'

 

After reading some seemingly similar errors online, I uninstalled the previous BB10 SDK, uninstalled and reinstalled the newest version several times, made sure the build configuration was set to debug-simulator, and made sure there were no spaces in the path name.  I'd also like to note that I get the "make" errors on a blank project with no other code immediately after typing ": public QObject" in a header file.

 

As I said, this is a basic project with code taken straight from the QML and C++ Integration page.  Here's the class header file:

 

#ifndef MYCLASS_H_
#define MYCLASS_H_
#include <QObject>
#include <QMetaType>
class MyClass : public QObject {
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
public:
MyClass();
virtual ~MyClass();
Q_INVOKABLE void reset();
int value();
void setValue(int i);
signals:
void valueChanged(int);
private:
int m_iValue;
};
#endif

 

 

and here's the class:

 

 

#include "MyClass.h"
MyClass::MyClass()
{
m_iValue = 0;
}
MyClass::~MyClass()
{
}
int MyClass::value()
{
return m_iValue;
}
void MyClass::setValue(int i)
{
m_iValue = i;
emit valueChanged(m_iValue);
}
void MyClass::reset()
{
m_iValue = 0;
emit valueChanged(m_iValue);
}

 

 

Here's MyExampleProject.cpp:

 
#include "MyExampleProject.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include "MyClass.h"
using namespace bb::cascades;
MyExampleProject::MyExampleProject(bb::cascades::Application *app)
: QObject(app)
{
// create scene document from main.qml asset
// set parent to created document to ensure it exists for the whole application lifetime
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
// create root object for the UI
AbstractPane *root = qml->createRootObject<AbstractPane>();
// set created root object as a scene
app->setScene(root);
MyClass *myObject = new MyClass();
qml->setContextProperty("myObject",myObject);
}
 

 The rest is what is created automatically with a new, blank C++/Cascades project.

 

 

 

 

 

Please use plain text.
Contributor
danjohnson
Posts: 18
Registered: ‎10-09-2012
My Device: Blackberry 10 Dev Alpha Simulator
My Carrier: Verizon

Re: Can't Build Sample C++/Cascades Project - make errors

Should this have been posted in "Native" instead?

Please use plain text.
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B
My Carrier: -

Re: Can't Build Sample C++/Cascades Project - make errors

Cascades is QML plus a C++ API and communication between the two environments.

That's kind of the point of Cascades.

 

I'd expect to see questions about the Cascades C++ API here.

 

Please use plain text.
Contributor
danjohnson
Posts: 18
Registered: ‎10-09-2012
My Device: Blackberry 10 Dev Alpha Simulator
My Carrier: Verizon

Re: Can't Build Sample C++/Cascades Project - make errors

I only asked because this (very similar) question was posted in Native:

 

Can't build sample Cascades app: Can't find qmake configuration file

 

On that topic, there seemed to be several unrelated solutions proposed in that thread, all of which I tried (except "reinstall Windows 7"... I'm hoping to not do that!)

Please use plain text.
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B
My Carrier: -

Re: Can't Build Sample C++/Cascades Project - make errors

That kind of error is usually a namespace thing. Ort at least when I've had it before it was.

 

Are you sure that MyClass is correctly referenced for its namespace?

Please use plain text.
Contributor
danjohnson
Posts: 18
Registered: ‎10-09-2012
My Device: Blackberry 10 Dev Alpha Simulator
My Carrier: Verizon

Re: Can't Build Sample C++/Cascades Project - make errors

I don't think so, but in case I'm missing something, beyond the code above, how could I check that?

 

As a note, if I create a new project, and simply add or modify any line of cascades-referencing code in the "[projectname].cpp" file (such as createRootObject or setScene) I again get the above-mentioned "make" errors, regardless of whether I created a class or did anything with it.  So this seems to be something more basic...

Please use plain text.
Developer
Zmey
Posts: 1,510
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Can't Build Sample C++/Cascades Project - make errors

After adding classes that inherit QObject you have to regenerate makefile adding the calls to MOC files for these new classes. Please try to Clean All & Rebuild.

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Contributor
danjohnson
Posts: 18
Registered: ‎10-09-2012
My Device: Blackberry 10 Dev Alpha Simulator
My Carrier: Verizon

Re: Can't Build Sample C++/Cascades Project - make errors

I have cleaned the workspace and rebuilt many times.  The errors go away after clean but return upon building.

Please use plain text.
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B
My Carrier: -

Re: Can't Build Sample C++/Cascades Project - make errors

Well here is a working version (tho I used a QString, not an int). It should put "hello" on the screen.

 

Try starting form this. Clean up the crud, and add your own stuff.

 

main.qml

 

// Default empty project template
import bb.cascades 1.0

// creates one page with a label
Page {
    Container {
        layout: DockLayout {}
        Label {
            text: myObject.value
            textStyle.base: SystemDefaults.TextStyles.BigText
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
    }
}

 

Test.hpp

// Default empty project template
#ifndef Test_HPP_
#define Test_HPP_

#include <QObject>

namespace bb { namespace cascades { class Application; }}

/*!
 * @brief Application pane object
 *
 *Use this object to create and init app UI, to create context objects, to register the new meta types etc.
 */
class Test : public QObject
{
    Q_OBJECT
public:
    Test(bb::cascades::Application *app);
    virtual ~Test() {}
};


#endif /* Test_HPP_ */

 

Test.cpp

 

// Default empty project template
#include "Test.hpp"

#include "MyClass.h"

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

using namespace bb::cascades;
using namespace play;

Test::Test(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    MyClass * myObject = new MyClass();
    qml->setContextProperty("myObject", myObject);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // set created root object as a scene
    app->setScene(root);
}

 

MyClass.h

/*
 * MyClass.h
 *
 *  Created on: Dec 20, 2012
 *      Author: Robert
 */

#ifndef MYCLASS_H_
#define MYCLASS_H_

#include <QObject>

#include <bb/cascades/Application>

using namespace bb::cascades;

namespace play {

class MyClass : public QObject {
Q_OBJECT
Q_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)

public:
	MyClass();
	virtual ~MyClass();
	QString value();
	void setValue(QString v);

	signals:
	void valueChanged(QString);

};

} /* namespace play */
#endif /* MYCLASS_H_ */

 

MyClass.cpp

/*
 * MyClass.cpp
 *
 *  Created on: Dec 20, 2012
 *      Author: Robert
 */

#include <bb/cascades/Application>


#include "MyClass.h"

using namespace bb::cascades;

namespace play {


MyClass::MyClass() : QObject()
{
	// TODO Auto-generated constructor stub

}

MyClass::~MyClass() {
	// TODO Auto-generated destructor stub
}


void MyClass::setValue(QString v) {

}

QString MyClass::value() {
	return (QString("hello"));
}


} /* namespace play */

 

main.cpp

// Default empty project template
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include <QLocale>
#include <QTranslator>
#include <Qt/qdeclarativedebug.h>
#include "Test.hpp"

using namespace bb::cascades;

Q_DECL_EXPORT int main(int argc, char **argv)
{
    // this is where the server is started etc
    Application app(argc, argv);

    // localization support
    QTranslator translator;
    QString locale_string = QLocale().name();
    QString filename = QString( "Test_%1" ).arg( locale_string );
    if (translator.load(filename, "app/native/qm")) {
        app.installTranslator( &translator );
    }

    new Test(&app);

    // we complete the transaction started in the app constructor and start the client event loop here
    return Application::exec();
    // when loop is exited the Application deletes the scene which deletes all its children (per qt rules for children)
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Please use plain text.
Contributor
danjohnson
Posts: 18
Registered: ‎10-09-2012
My Device: Blackberry 10 Dev Alpha Simulator
My Carrier: Verizon

Re: Can't Build Sample C++/Cascades Project - make errors

Thank you very much for your response (and for making that project to test!)

 

I built your example project fine with no issues.  Since mine is very similar but still giving those "make" errors, I looked for differences and I noticed the difference is the inclusion of namespace play in your example.  (That seems to be the only difference.)

 

After adding those references to my project (adding "using namespace std;" and "namespace play {") I am still getting those make errors, plus the following:

 

'play' is not a namespace-name

expected namespace-name before ';' token

 

So this may be at the heart of this weirdness, but I don't understand what is different... as mentioned, both the project I am trying to get to work, as well as the test one using your code, were created new today, so it can't be some build property issue from importing an old project or something like that.

 

I'll investigate this further, but in any case, thank you again for your time!

 

 

Please use plain text.