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

Serializing my custom class in Qt

i use Reading/writing QObjects is it true? i serialize a class with it but when deserialize it isn't the original class! what can i do? this is my base class header: class Base : public QObject { Q_OBJECT public: explicit Base(QObject…
Erfan Tavakoli
  • 336
  • 1
  • 6
  • 14
17
votes
11 answers

Q_OBJECT linker error!

I am receiving the following linker error when I build my application. HIMyClass.obj:: error: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CHIMyClass::metaObject(void)const " …
liaK
  • 11,422
  • 11
  • 48
  • 73
17
votes
1 answer

How heavy is QObject really?

I recently posted a question about the overhead of QObject in typical usage scenarios, but unfortunately the question got closed as a duplicate of another question that didn't technically answer the question. What is worse, the hasty "Samaritans"…
dtech
  • 47,916
  • 17
  • 112
  • 190
15
votes
7 answers

Qt: Can child objects be composed in their parent object?

In Qt, can I embed child widgets in their parent via composition, or do I have to create them with new? class MyWindow : public QMainWindow { ... private: QPushButton myButton; } MyWindow::MyWindow () : mybutton("Do Something", this) { …
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
14
votes
3 answers

How can I get the QObject::deleteLater() to zero the object?

Normally when I delete an object I set it to zero. This helps in that I code my routines to check the object is not zero then proceed. However if I use the deleteLater() function I have lost control of it. I don't know if its a valid item or if I…
Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
14
votes
1 answer

How to expose C++ structs for computations to Qml

I have the following problem. I am developing a model in C++ and a View in Qml, connecting them via Controllers. In my model I perform multiple calculations. I also offer users of my application the possibility, to write custom event handlers,…
MattW
  • 461
  • 3
  • 10
14
votes
2 answers

How to remove QObject from parent

How can I break parent-child ownership for a QObject? It seems that there is no longer an explicit way of doing this. Is it enough to call QObject::setParent(NULL)
BigONotation
  • 4,406
  • 5
  • 43
  • 72
14
votes
1 answer

Difference between QObject::connect vs connect methods

I am a newbie with Qt. Most of the times Qt developers need to use signals and slots for object communication. I have seen two ways of connecting signals and slots so far. 1)QObject::connect(scrollBar, SIGNAL(valueChanged(int)),label, …
DesirePRG
  • 6,122
  • 15
  • 69
  • 114
13
votes
3 answers

How do I copy object in Qt?

I'm using Qt and have some real basic problems. I have created my own widget MyTest that have a variable obj. I need to set this variable obj from an object outside of the widget so that the variable is copied not just a pointer to another object. I…
Martin
  • 1,675
  • 11
  • 34
  • 46
12
votes
2 answers

How to pass Qt::ConnectionType to QObject::connect when connecting a lambda?

I am connecting lambdas to QObject's signals: QObject::connect(handle, &BatchHandle::progressMax, [this](const ProcessHandle* const self, const int value) { this->maxProgress(value); }); The code above compiles with no…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
11
votes
1 answer

Is it possible to mix template-derived C++ classes with Qt's Q_OBJECT?

In my application, I have the following class hierarchy: class Word { ... } template class Dictionary { ... }; class WordDictionary : public Dictionary { Q_OBJECT ... } The WordDictionary class parses a…
neuviemeporte
  • 6,310
  • 10
  • 49
  • 78
11
votes
3 answers

How to bind C++ property to QML property?

So I know how to bind QML property to C++ property, so when C++ one calls notify signal, QML updates the view. Is there any way to make C++ property update when user changes something using UI? For example, I have a Combobox, and I want some C++…
Rinat Veliakhmedov
  • 1,021
  • 1
  • 19
  • 36
11
votes
3 answers

Qt: Specifying multiple connection types with QObject::connect

I wanted to know if it is possible to specify multiple connection types. For example, I want my connection type to be a queued connection and a unique connection. Is it possible to specify that in one statement…
MistyD
  • 16,373
  • 40
  • 138
  • 240
10
votes
1 answer

fail to use Q_OBJECT Macro in CMake Project

I am having trouble with the meta Object Compiler of Qt in my CMake Project. A shared lib I am building contains the following code and employs the pimpl idiom. After invoking CMake and upon compilation I get AUTOGEN: error:…
CD86
  • 979
  • 10
  • 27
10
votes
2 answers

How to check whether or not a dynamic property exists

I have use setProperty function to set dynamic property to object. But I want in other place to check if the property that was created is exists or not. What I done: When set the property: QString fileDlg = QFileDialog::getOpenFileName(this, "Open…
Lion King
  • 32,851
  • 25
  • 81
  • 143
1
2
3
27 28