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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany
Accepted Solution

Extending QObject results in undefined reference to vtable error

I have an existing bean-type class with several QStrings and bool members, and one QStringList.

As i want to access its properties from QML i want to use QObject.

 

The class compiles fine without the QObject extension, but when i add it i get "undefined reference to 'vtable for X'

 

So this class compiles:

/*
 * X.hpp
 *
 *  Created on: 08.11.2012
 *      Author: sha
 */

#ifndef X_HPP_
#define X_HPP_

#include <QString>
#include <QObject>

class X {
private:
	QString name;
public:
	X();
	QString getName() const;
	void setName(QString name);
};


#endif /* X_HPP_ */

 And this does not:

/*
 * X.hpp
 *
 *  Created on: 08.11.2012
 *      Author: sha
 */

#ifndef X_HPP_
#define X_HPP_

#include <QString>
#include <QObject>

class X: public QObject {
Q_OBJECT

private:
	QString name;
public:
	X();
	QString getName() const;
	void setName(QString name);
};


#endif /* X_HPP_ */

 Any idea why?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Extending QObject results in undefined reference to vtable error

Most probably it compiles fine but linker fails. This is because you have to moc-process your X.hpp and add generated moc_X.cpp (or whatever file will be generated) to your project. It has already been covered on this forum.

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Extending QObject results in undefined reference to vtable error

ok, i guess i have found the post:
http://supportforums.blackberry.com/t5/Native-Development/undefined-reference-to-vtable-for/m-p/1624...

can you tell me how to run the moc command?
I am currently using Momentics, without any command line stuff.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Extending QObject results in undefined reference to vtable error

Unfortunately it is a pain for PlayBook.

To run moc you first of all have to have it. As far as I know Qt libraries were included in the latest SDK2.1 for PlayBook but (surprise!) there is not qmake or moc or any other Qt tools. You could probably find these tools but moc is very sensitive to versioning, so you have to find moc exactly the same version that libraries you have.

Hopefully Qt guys that happen to visit this forum can give you an advice.

When I developed Qt app I cloned it from their repo and built Qt on my local dev machine.

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Extending QObject results in undefined reference to vtable error

I am building for BB10 using NDK 10.0.9.386, and i have found moc.exe in C:\bbndk\host_10_0_9_52\win32\x86\usr\bin

i have executed it as described in the linked thread, it has created a moc_x.cpp and it compiles now.

However, it seems that for this issue there were incorrect HEADER members in the pro file.
For whatever reason this did not disturb Momentics in any way, until i added QObject in one of the files.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Extending QObject results in undefined reference to vtable error

What's this:

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."

 

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Extending QObject results in undefined reference to vtable error

Peter Strange is a fellow developer (from the java subforum, as I am...)

He wrote that some day, wanting to write "automatically", i guess.
Personally, i found it amusing, but it seems to be very specific to my humor as numerous people have asked me about it already.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter