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
10
votes
1 answer

Get a list of all QObjects created in a Application

To get a list of all the QWidgets created in an application we can simply call QApplication::allWidgets(). I've read the documentation, and I haven't found anything like this to get a list of all QObjects. If an application creates stand-alone…
BetterWalk
  • 101
  • 1
  • 4
10
votes
1 answer

Qt 5 assign slot with parameters to a QPushButton

I have a Qt application on C++ and I want to assign a slot to a QPushButton. But I want to pass some arguments because I have more than one QPushButton doing similar thing so I want one function but with a parameter in it but Qt keeps saying me that…
Bankin
  • 777
  • 1
  • 16
  • 31
10
votes
1 answer

What is the right way to suppress Qt signals when values are explicitely set

I got a from QWidget derived class that holds three QSpinBoxes (e.g. coordinates). The valueChanged() signal is connected and is emitted in at least these three cases: up/down button manually entered number setValue() However, when using…
braggPeaks
  • 1,158
  • 10
  • 23
9
votes
6 answers

QT: Is it a good idea to base my domain objects on QObject?

I'm reasonably new to using the QT framework in combination with C++. I was wondering: Is it a good idea to base my domain classes on QObject? Or should I only do this for classes higher up in the hierarchy? (closer to the user interface level). The…
StanB123
  • 477
  • 5
  • 14
9
votes
1 answer

How to pass QObject as argument from signal to slot in Qt connect

My original code passed a QStringList from the signal to the slot and then returned a QList . Everything worked fine but I needed to change both the QStringList and QList into 2 different subclassed QObjects. Since then I have been receiving errors…
luxtor
  • 115
  • 1
  • 2
  • 4
9
votes
2 answers

QSharedPointer and QObject::deleteLater

I have a situation where a QSharedPointer managed object signalizes that it has finished it's purpose and is ready for deletion soon (after execution left the function emitting my readyForDeletion signal). When working with normal pointers, I'd just…
athre0z
  • 442
  • 4
  • 12
9
votes
2 answers

QThread finished() connected to deletelater of a QObject

I have thought a lot and read lot of articles before asking this question here. None of the articles gave me a proper answer. http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ QThread* thread = new…
Srikan
  • 2,161
  • 5
  • 21
  • 36
8
votes
1 answer

Where is Qt’s PointerToMemberFunction defined?

In this question I was able to adapt the QObject method QMetaObject::Connection QObject::connect(const QObject * sender, const char * signal, const QObject * receiver, const char * method, Qt::ConnectionType type =…
bdesham
  • 15,430
  • 13
  • 79
  • 123
8
votes
2 answers

How to obtain the set of all signals for a given widget?

I am looking through the Qt documentation. Is there a quick and dirty way to get a list of all signals that a widget can emit. For example (withPyQt): allSignalsList = thisWidget.getSignals() Alternatively, is there is a nice place on the new Qt5…
ADB
  • 1,210
  • 4
  • 15
  • 23
8
votes
2 answers

Do QObject derived types need a parent QObject?

I am writing some Qt class which is derived from QObject, it looks like: class A : public QObject { Q_OBJECT public: A() : QObject() {} ..... } but in several places I saw, that the QObject derived classes all have a parent, like: class A :…
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
8
votes
1 answer

Does QObject distinguish between stack and heap allocated children when deleting?

According to the Qt documentation: QObjects organize themselves in object trees. When you create a QObject with another object as parent, the object will automatically add itself to the parent's children() list. The parent takes ownership of…
dtech
  • 47,916
  • 17
  • 112
  • 190
7
votes
3 answers

C++ Qt Reflection with Copy and Assignment

As the QObject documentation and many others explain, a QObject has an identity and thus hides its copy constructor and assignment operator. However, I'm not deriving from QObject for its dynamic properties feature or the signals/slots feature. I…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
7
votes
2 answers

QObject cloning

I know that Qobjects are supposed to be identities not values eg you cannot copy them and by default the copy constructor and assignment are disabled as explained in qt documentation. But is it possible to create a new QObject from an existing one…
Olorin
  • 395
  • 1
  • 4
  • 12
7
votes
3 answers

Is there a way to uninstall eventfilter in qt?

I need event filter only for some time, is there a way of uninstalling it later on?
MarcinG
  • 840
  • 6
  • 21
6
votes
1 answer

Looping QProgressBar gives error >> QObject::installEventFilter: Cannot filter events for objects in a different thread

This question seems to have been asked many times in many different forms but I haven't managed to find one with a -relevant to my code- solution. When I run the program it shows QObject::installEventFilter: Cannot filter events for objects in a…
Jay
  • 3,373
  • 6
  • 38
  • 55
1 2
3
27 28