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
18
votes
3 answers

PyQt: Connecting a signal to a slot to start a background operation

I have the following code that performs a background operation (scan_value) while updating a progress bar in the ui (progress). scan_value iterates over some value in obj, emitting a signal (value_changed) each time that the value is changed. For…
Hernan
  • 5,811
  • 10
  • 51
  • 86
17
votes
1 answer

If a Qt signal is emitted in the forest and noone is around to hear it, does it make a sound?

Sorry for the humorous phrasing of the question. I couldn't resist ;-) If I emit a signal that's not connected to a slot anywhere in the code, is there still a performance cost associated with that "emission". I'm not familiar with the mechanism via…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
17
votes
4 answers

Deletion of objects send by signals, Ownership of objects in signals, Qt

Here, my signal declaration: signals: void mySignal(MyClass *); And how I'm using it: MyClass *myObject=new myClass(); emit mySignal(myObject); Here comes my problem: Who is responsible for deletion of myObject: Sender code, what if it…
metdos
  • 13,411
  • 17
  • 77
  • 120
16
votes
5 answers

Using Qt signals and slots vs calling a method directly

Lets say I have a main window with a slider and a widget inside that window with a method called setValue(int). I'd like to call this method every time the value of the slider has changed. Is there any practical difference between the two following…
jaho
  • 4,852
  • 6
  • 40
  • 66
16
votes
1 answer

Define pyqt4 signals with a list as argument

According to http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html I can define a pyqt4-signal with takes an integer argument by mysignal = pyqtSignal(int). How can I define a signal which takes an integer and a list of strings or…
student
  • 1,636
  • 3
  • 29
  • 53
16
votes
1 answer

Qt Model/View/Controller Example

I am just getting started in Qt, and trying to get a simplified, working example of the model-view-controller design pattern. So far, I have been able to use signals and slots to connect basic widgets like push buttons to a QLabel, and have the view…
nairware
  • 3,090
  • 9
  • 37
  • 58
16
votes
2 answers

PyQt4: combine textChanged and editingFinished for QLineEdit

Is there a way to combine textChanged and editingFinished for QLineEdit? The problem is that editingFinished is emitted even if I only move the cursor away from QLineEdit without any changes. Whereas I want to emit a signal only when any changes…
Ekaterina Mishina
  • 1,633
  • 5
  • 20
  • 23
16
votes
4 answers

QT + How to call slot from custom C++ code running in a different thread

I am new to QT and I am doing some learning. I would like to trigger a slot that modify a GUI widget from a C++ thread(Currently a Qthread). Unfortunatly I get a: ASSERTION failed at: Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());…
xcimo
15
votes
3 answers

Connect signals to slots with constant values

To connect signals to slots, as far as I know, the parameters of the signal need to match the parameters of the slot. So for example: connect(dockWidget->titleBarWidget(), SIGNAL(closeButtonClicked()), ui->sideControls,…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
15
votes
1 answer

How to set value of a widget without triggering valueChanged callback in PySide?

I want to update a widget's value but in order to prevent infinite loops, I need to prevent calling the callback function of this widget's .valueChanged signal. Following example works entirely as expected: Qt = PySide class MainWindow(Actor,…
ceremcem
  • 3,900
  • 4
  • 28
  • 66
15
votes
1 answer

Event loops and signal-slot processing when using multithreading in Qt

I've been having some problems with using QThreads which made me explore different combinations before I've found the right one. However I still don't fully understand what is really happening in the four cases shown below when it comes to event…
Moomin
  • 1,846
  • 5
  • 29
  • 47
15
votes
2 answers

PySide: Easier way of updating GUI from another thread

I have a PySide (Qt) GUI which spawns multiple threads. The threads sometimes need to update the GUI. I have solved this in the following way: class Signaller(QtCore.QObject) : my_signal = QtCore.Signal(QListWidgetItem, QIcon) signaller =…
Petter
  • 37,121
  • 7
  • 47
  • 62
15
votes
5 answers

Is it valid to define a pure virtual signal in C++/Qt?

I am making an abstract-base-class and was thinking I might want a pure virtual signal. But when I compiled I get a warning for the pure virtual signals I have defined: ../FILE1.h:27: Warning: Signals cannot be declared virtual ../FILE1.h:28:…
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
14
votes
4 answers

Sending signal from static class method in Qt

I am trying to code a static callback function that is called frequently from another static function within the same class. My callback function needs to emit a signal but for some reason it simply fails to do so. I have put it under a debugger and…
user99545
  • 1,173
  • 3
  • 16
  • 32
14
votes
3 answers

Qt issue passing arguments to slot

I can't seem to pass an argument to a slot. If I don't pass an argument, the function rolls through fine. If I pass an argument (integer), I get the errors "No such name type" and "No such slot" when I compile. In my header, I declare: private…
user375566