Reputation: 2326
I'm trying to adapt a simple example from qt (Using qt creator 3.5.1, from qt 5.5.1) to create a new qml type. Here's the trivial new type:
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
public:
Person(QObject *parent = 0): QObject(parent), m_shoeSize(0) {}
QString name() const { return m_name; }
void setName(const QString & name) { m_name = name; }
int shoeSize() const { return m_shoeSize; }
void setShoeSize(int s) { m_shoeSize = s; }
private:
QString m_name;
int m_shoeSize;
};
When I try to register it:
qmlRegisterType<Person>("People", 1,0, "Person");
I get
Undefined symbols for architecture x86_64:
"Person::qt_metacall(QMetaObject::Call, int, void**)", referenced from: vtable for QQmlPrivate::QQmlElement in main.o "Person::qt_metacast(char const*)", referenced from: ...
I think I need to add a "library" to the .pro file, but I'm at a loss. Any ideas?
I already have the following:
QT += core qml quick widgets
Upvotes: 0
Views: 1160
Reputation: 2326
As suggested by tpr: The example had Person in a separate .h/.cpp file. When I did that, the program successfully compiled. Did not expect that.
Upvotes: 1