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
Developer
simon_hain
Posts: 16,097
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
Please use plain text.
Developer
BGmot
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.

Please use plain text.
Developer
simon_hain
Posts: 16,097
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
Please use plain text.
Developer
BGmot
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.

Please use plain text.
Developer
simon_hain
Posts: 16,097
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
Please use plain text.
Developer
BGmot
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."

 

Please use plain text.
Developer
simon_hain
Posts: 16,097
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
Please use plain text.