Questions tagged [signals-slots]

Signals and slots is a mechanism for implementing the observer pattern.

Signals and slots is a mechanism for implementing the observer pattern. It has many implementations in various languages:

See also:

1653 questions
34
votes
3 answers

Is it possible to connect a signal to a static slot without a receiver instance?

Is it possible to connect a signal to static slot without receiver instance? Like this: connect(&object, SIGNAL(some()), STATIC_SLOT(staticFooMember())); There is a QApplication::closeAllWindows() function with [static slot] attribute in Qt…
bartolo-otrit
  • 2,396
  • 3
  • 32
  • 50
34
votes
3 answers

Determine signals connected to a given slot in Qt

I've injected myself into a Qt application, and I'm attempting to figure out what signals a given slot is connected to, but can't find any information on doing this. Is there a mechanism for doing this out of the box? If so, is this exposed to…
Serafina Brocious
  • 30,433
  • 12
  • 89
  • 114
33
votes
3 answers

PyQt Widget connect() and disconnect()

Depending on a conditions I would like to connect/re-connect a button to a different function. Let's say I have a button: myButton = QtGui.QPushButton() For this example let's say I check if there is an internet connection. if connected == True: …
alphanumeric
  • 17,967
  • 64
  • 244
  • 392
33
votes
3 answers

const-ref when sending signals in Qt

This is a thing that I never quite got with const-ref and I really hope that someone could explain it to me. When calling a function inside of another function, I get that const-ref is the best way when passing stack objects that I don't plan to…
chikuba
  • 4,229
  • 6
  • 43
  • 75
29
votes
2 answers

Why do I need to decorate connected slots with pyqtSlot?

I'm using pyqt5, and I have several methods connected using code similar to the following: self.progress.canceled.connect(self.cancel) Where, for example, self.cancel is: def cancel(self): self.timer.stop() This code seems to work cleanly in…
NirIzr
  • 3,131
  • 2
  • 30
  • 49
29
votes
5 answers

Qt signaling across threads, one is GUI thread?

What does it mean to move a object from one thread to another in Qt using moveToThread? Everything seems to work even before using moveToThread, which moves the object from one thread (GUI thread) to a another thread ( worked) and Qt:connect calls…
Passionate programmer
  • 5,748
  • 10
  • 39
  • 43
29
votes
3 answers

Does it make any difference, using public slots instead of private slots in Qt?

In C++, public means those members that are accessible from anywhere where the object is visible, private means that members are accessible only from within other members of the same class or from their friends. But in Qt, the difference in private…
罗泽轩
  • 1,603
  • 2
  • 14
  • 19
28
votes
4 answers

stack object Qt signal and parameter as reference

May I have a "dangling reference" with the following code (in an eventual slot connected to the myQtSignal)? class Test : public QObject { Q_OBJECT signals: void myQtSignal(const FooObject& obj); public: void sendSignal(const…
Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
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
27
votes
2 answers

qt QWidget click

I have my own class based in QWidget. I put this widget in QMainWindow and I need catch mouse click on this widget. I tried: connect(my_widget, SIGNAL(clicked()), this, SLOT(exit(0))); But nothing is happening. How can I do it?
0xAX
  • 20,957
  • 26
  • 117
  • 206
27
votes
6 answers

What are signals and slots?

Can someone explain in simple terms the "signals and slots" pattern?
JeffV
  • 52,985
  • 32
  • 103
  • 124
27
votes
5 answers

Qt: meaning of slot return value?

According to the documentation the return value from a slot doesn't mean anything. Yet in the generated moc code I see that if a slot returns a value this value is used for something. Any idea what does it do? Here's an example of what I'm talking…
shoosh
  • 76,898
  • 55
  • 205
  • 325
26
votes
2 answers

Qt Signals and Slots object disconnect?

I am wondering if i need to disconnect singals and slots if i destroy the signal emitting object. Here is an example: QAudioOutput * audioOutput = new…
Anton
  • 1,181
  • 2
  • 17
  • 27
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
24
votes
2 answers

Argument type for Qt signal and slot, does const reference qualifiers matters?

For signal and slot of below type signals: void textChanged(const QString &); public slots: void setText(const QString & text) the type of argument of textChanged and setText seems to work invarable of const and &. Does the constant and…
yesraaj
  • 46,370
  • 69
  • 194
  • 251