Questions tagged [qt-signals]

Signals and slots are used for communication between objects. The signals and slots mechanism is a central feature of Qt and probably the part that differs most from the features provided by other frameworks.

Signals are emitted by an object when its internal state has changed in some way that might be interesting to the object's client or owner. Only the class that defines a signal and its subclasses can emit the signal.

When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop. Execution of the code following the emit statement will occur once all slots have returned.

Signals are automatically generated by the moc and must not be implemented in the .cpp file. They can never have return types (i.e. use void).

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5 (note about new signal syntax in Qt5). Also, here is documentation for using signals for QML.

507 questions
82
votes
4 answers

How delete and deleteLater works with regards to signals and slots in Qt?

There is an object of class QNetworkReply. There is a slot (in some other object) connected to its finished() signal. Signals are synchronous (the default ones). There is only one thread. At some moment of time I want to get rid of both of the…
stach
  • 2,135
  • 2
  • 20
  • 22
71
votes
3 answers

How to get sender widget with a signal/slot mechanism?

It's possible to bind more than one signal to one slot (isn't?). So, is there a way to understand which widget sends the signal? I'm looking for something like sender argument of events in .NET
sorush-r
  • 10,490
  • 17
  • 89
  • 173
62
votes
3 answers

How to emit cross-thread signal in Qt?

Qt documentation states that signals and slots can be direct, queued and auto. It also stated that if object that owns slot 'lives' in a thread different from object that owns signal, emitting such signal will be like posting message - signal emit…
grigoryvp
  • 40,413
  • 64
  • 174
  • 277
58
votes
3 answers

Qt signals (QueuedConnection and DirectConnection)

I'm having trouble with Qt signals. I don't understand how DirectConnection and QueuedConnection works? I'd be thankful if someone will explain when to use which of these (sample code would be appreciated).
Nika
  • 1,864
  • 3
  • 23
  • 44
58
votes
1 answer

Are signals in Qt automatically disconnected when one of the class is deleted

Does Qt automatically remove connections between objects , when one of the side is deleted ? e.g connect (A .. , B ..) , when A (a pointer) is deleted , or B is deleted , will the connection be disconnected ? Is it necessary to use disconnect…
daisy
  • 22,498
  • 29
  • 129
  • 265
46
votes
8 answers

Can Qt signals be public, protected or private?

Can Qt signals be public, protected or private? Can I create internal signals, which are seen only inside the class? Update: I have a class with some internal signals. How can I make those signals invisible for other classes (encapsulation &…
anton
  • 755
  • 2
  • 7
  • 9
44
votes
4 answers

Declare abstract signal in interface class

How to declare a Qt signal in an abstract class / interface when the implementing class is already derrived from QObject/QWidget? class IEmitSomething { public: // this should be the signal known to others virtual void…
Beachwalker
  • 7,685
  • 6
  • 52
  • 94
35
votes
3 answers

My signal / slot connection does not work

I repeatedly see people having problems with slots not being called. I would like to collect some of the most common reasons. So maybe I can help people and avoid a lot of redundant questions. What are reasons for signal / slot connections not…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
28
votes
3 answers

Qt signals and slots: permissions

There are discrepancies between respected answers here on SO and the actual Qt docs. I've read this question and I want some further clarification. Can anyone confirm: A signal is always protected, therefore it can be emitted only by the class or…
johnbakers
  • 24,158
  • 24
  • 130
  • 258
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
25
votes
8 answers

How to Compress Slot Calls When Using Queued Connection in Qt?

After reading some articles like this about Qt Signal-Slot communications I still have a question concerning the queued connection. If I have some threads sending signals all the time to each other and lets say one thread_slowis running a slow…
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
24
votes
5 answers

When to use signals and slots and when not to

We're using Qt that offers signals and slots which I find really convenient. However, with great power comes great responsibility and I think it's very easy too misuse this feature. Are there any best-practices for signal-slot usage? I'm having a…
larsmoa
  • 12,604
  • 8
  • 62
  • 85
22
votes
3 answers

QObject connection function

I checked other similar questions and tried their solutions but they don't work for me. I'm basically trying to make a http client that only makes post requests. In order to do this, I need to connect QNetworkManager's finished signal to some…
CTheDark
  • 2,507
  • 3
  • 18
  • 18
22
votes
2 answers

qt signal undefined reference error

I have a class server for which I have created a signal joined(QString name). I call it in a function called join(QString name), however I'm getting the error Server.o: In function Server::join(QString)': Server.cpp:(.text+0x48): undefined…
Amre
  • 1,630
  • 8
  • 29
  • 41
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
1
2 3
33 34