Questions tagged [qobject]

QObject is a Qt class which serves as a base class for all Qt objects.

QObject is the center of Qt object model. QObjects are organized as trees, where one objects can become parents to others, taking ownership for them, and being responsible for freeing heir children's resources on deletion.

Each QObject has a name, which can be accessed. It also provides a way to search in, or to iterate through it's children. Objects can also receive and filter events.

When deriving a class from QObject, one must remember to include a special Q_OBJECT macro in a private section of the class, which is a mandatory for every class that uses signals and slots, or any other features of Qt's meta-object system.

A QObject instance is said to have a thread affinity, or that it lives in a certain thread. When a QObject receives a queued signal or a posted event, the slot or event handler will run in the thread that the object lives in.

Official documentation of QObject can be found here.

410 questions
88
votes
27 answers

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

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…
Mohsen Zahraee
  • 3,309
  • 5
  • 31
  • 45
71
votes
9 answers

Qt Linker Error: "undefined reference to vtable"

This is my header: #ifndef BARELYSOCKET_H #define BARELYSOCKET_H #include //! The First Draw of the BarelySocket! class BarelySocket: public QObject { Q_OBJECT public: BarelySocket(); public slots: void sendMessage(Message…
Thomas
  • 1,545
  • 3
  • 14
  • 25
54
votes
4 answers

When should Q_OBJECT be used?

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…
Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
35
votes
1 answer

Is it possible to disconnect all of a QObject's connections without deleting it

I have a QObject A, this is connected to another QObject B. Now I want A to connect to C, a third QObject and to completely disconnect from B. Easy peasy! Trouble is I have a lot of of A's each with their own set of signals and slots (B's/C's are…
Troyseph
  • 4,960
  • 3
  • 38
  • 61
30
votes
5 answers

PyQt: RuntimeError: wrapped C/C++ object has been deleted

If I run this code: #!/usr/local/bin/ python3 import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class Window(QMainWindow): def __init__(self): super().__init__() self.button1 = QPushButton("1") …
Brian
  • 3,453
  • 2
  • 27
  • 39
29
votes
2 answers

What is qobject_cast?

Could someone explain in as simple terms as possible (or as simple as you would like) what qobject_cast is, what it does and why we would need to cast one class type to another? Like, I get typecasting in the sense of casting an int as a char or…
Michael Thomas
  • 443
  • 1
  • 4
  • 8
25
votes
1 answer

Qt interfaces or abstract classes and qobject_cast()

I have a fairly complex set of C++ classes that are re-written from Java. So each class has a single inherited class, and then it also implements one or more abstract classes (or interfaces). Is it possible to use qobject_cast() to convert from a…
Timothy Baldridge
  • 10,455
  • 1
  • 44
  • 80
25
votes
1 answer

What is the significance of Q_PROPERTY in Qt?

I am not able to understand the usage of Q_PROPERTY. How th Q_PROPERTY helps in making a program defensive? What is it used for? I have seen the forum, but really not able to make its applicaton. I have understood the example, but not it's…
dexterous
  • 6,422
  • 12
  • 51
  • 99
23
votes
2 answers

Tracking mouse move in QGraphicsScene class

I subclassed QGraphicsScene and added method mouseMoveEvent to handle mouse move event. I created a ruler on top of GraphicsView and have the ruler tracking mouse movement. In the QGraphicsScene::mousemoveEvent I calls mouseMoveEvent of the ruler…
cuteCAT
  • 2,251
  • 4
  • 25
  • 30
22
votes
2 answers

How can I create a new window from within QML?

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 { …
opatut
  • 6,708
  • 5
  • 32
  • 37
20
votes
1 answer

Repeating Q_DISABLE_COPY in QObject derived classes

In Qt there is a macro that allows declaring private copy constructurs and assignment operators for classes: http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#Q_DISABLE_COPY It is said that this macro should be used for all QObject (especially…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
19
votes
6 answers

How to use SIGNAL and SLOT without deriving from QObject?

OR other way to formulate my question (though it didn't solve my problem): 'QObject::QObject' cannot access private member declared in class 'QObject' I need SIGNALs and SLOTS functionality in my class, but I assume it is not possible without to…
6e69636b6e616d65
  • 211
  • 1
  • 2
  • 9
19
votes
4 answers

No matching function for QObject::connect

I'm writing a program that send an UDP frame every 10 mS. Here's how my program is supposed to work : I've got a client class : //Constructor clientSupervision::clientSupervision() { } void clientSupervision::sendDataUDP(){ //Create a frame and…
Evans Belloeil
  • 2,413
  • 7
  • 43
  • 76
18
votes
3 answers

'PySide.QtCore.Signal' object has no attribute 'connect'

I am using Python 3.4 with Pyside 1.2.4 and PyQt 4.8.7 and when I try to connect a Signal to a Slot it says: 'PySide.QtCore.Signal' object has no attribute 'connect' Im am using MVC: Model: from PySide.QtCore import Signal class Model(object): …
LimitX
  • 595
  • 3
  • 7
  • 23
18
votes
1 answer

Proper way to check QObject derived class type in Qt

Lets say I have a two classes: class A : public QObject {}; class B : public QObject {}; then I go QObject *a = new A(); QObject *b = new B(); now, how do I make sure that "a" is an instance of class A, and "b" is an instance of class…
ak.
  • 3,329
  • 3
  • 38
  • 50
1
2 3
27 28