qobject

How can I create a new window from within QML?

一个人想着一个人 提交于 2019-11-27 01:53:14
问题 Is there a way to create a completely new window instance, as a child window of the main QML window in a QmlApplication? // ChildWindow.qml Rectangle { id: childWindow width: 100 height: 100 // stuff } // main.qml Rectangle { id: window width: 1000 height: 600 MouseArea { anchors.fill: parent onClicked: createAWindow(childWindow); } } I am trying to avoid writing a Q_OBJECT class just for instanciating the new window within a new QmlApplicationViewer . 回答1: There is no way to create top-level

When should Q_OBJECT be used?

送分小仙女□ 提交于 2019-11-26 20:19:52
The documentation states that: The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system. But exactly what does that mean? On which QObject-derived classes can I safely omit it? Will problems arise if you omit Q_OBJECT on a QObject-derived class, and then inherit from that one? Basically I would like a little more information on when I can omit it from my Qt classes. liaK You should use the Q_OBJECT macro for any non-templated classes that derive from QObject . Besides

Unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Parent

China☆狼群 提交于 2019-11-26 15:19:13
问题 I inherited a class from QObject : class Parent: public QObject { Q_OBJECT QObject* cl; public: Parent(QObject *parent=0):QObject(parent) { cl = NULL; } QObject* getCl() const { return cl; } void setCl(QObject *obj) { cl = obj; } }; But when I write : Parent ev; I get the following error: main.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Parent::metaObject(void)const " (?metaObject@Parent@@UBEPBUQMetaObject@@XZ) main.obj:-1: error:

Qt Linker Error: “undefined reference to vtable” [duplicate]

a 夏天 提交于 2019-11-26 00:38:08
问题 This question already has an answer here: Undefined reference to vtable. Trying to compile a Qt project 17 answers This is my header: #ifndef BARELYSOCKET_H #define BARELYSOCKET_H #include <QObject> //! The First Draw of the BarelySocket! class BarelySocket: public QObject { Q_OBJECT public: BarelySocket(); public slots: void sendMessage(Message aMessage); signals: void reciveMessage(Message aMessage); private: // QVector<Message> reciveMessages; }; #endif // BARELYSOCKET_H This is my class: