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
14
votes
2 answers

Debug Qt signals, slots and connections

Is there a way to see which signals are fired, and if there is a slot connected to them? Ideally, we'd like to see all signals, not just those of a particular class or method; e.g. QSignalSpy only allows us to track specific signals of specific…
Ivo
  • 3,481
  • 1
  • 25
  • 29
14
votes
1 answer

How to bind to a signal from a delegate component within a ListView in QML

Let's say I have a ListView of clickable delegate components (or GridView or Repeater). These delegate components need to emit a signal along with custom data when triggered that can be picked up by the parent of the ListView. How can this signal…
Paul Masri-Stone
  • 2,843
  • 3
  • 29
  • 51
14
votes
2 answers

How to use templates with QT signals and slots?

I want to use signals and slots in my program, but unfortunately they should be used for transmitting several different data types (e.g. QString, double, etc.) and I don't want to write twenty different slots just because I need one for each data…
arc_lupus
  • 3,942
  • 5
  • 45
  • 81
13
votes
2 answers

Creating a dynamic slot in Qt

I am trying to create slots dynamically and connect them. I am able to dynamically create pushButtons and connect them with existing slots. But what if I have a class with some member functions and I want to use these functions as slots. From a…
Chenna V
  • 10,185
  • 11
  • 77
  • 104
13
votes
4 answers

Are "public slots:" sections still necessary in Qt5?

A simple question regarding the new signal/slot syntax in Qt5: Are there still benefits for a Q_OBJECT-derived class to have public slots: sections declared? Note: With the new syntax you're able to connect a signal to any public function of a…
FlKo
  • 805
  • 1
  • 10
  • 27
13
votes
3 answers

Connecting slots and signals in PyQt4 in a loop

Im trying to build a calculator with PyQt4 and connecting the 'clicked()' signals from the buttons doesn't work as expected. Im creating my buttons for the numbers inside a for loop where i try to connect them afterwards. def __init__(self): for…
lukad
  • 17,287
  • 3
  • 36
  • 53
13
votes
3 answers

Implementing signals (Observer pattern): is mutable or const_cast necessary?

I'm implementing my very own signal/slot (observer pattern, Qt style) mechanism so I can have a property that notifies ... stuff... that is has changed. I think C++11 provides everything necessary to make a very succint and featureful implementation…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
13
votes
5 answers

Public functions versus public slots

In my one year of Qt programming, I have learnt a lot about signals and slots. But not enough... http://doc.qt.io/qt-5/signalsandslots.html Slots can be used for receiving signals, but they are also normal member functions. So... Is there any…
Thalia
  • 13,637
  • 22
  • 96
  • 190
13
votes
2 answers

PyQt Connect to KeyPressEvent

Certain widgets will allow me to do: self.widget.clicked.connect(on_click) but doing: self.widget.keyPressEvent.connect(on_key) will fail saying that the object has no attribute 'connect'. I know that sub-classing the widget and re-implementing…
jpcgt
  • 2,138
  • 2
  • 19
  • 34
13
votes
2 answers

How to connect the signal valueChanged from QLineEdit to a custom slot in Qt

I need to connect the valueChanged signal from QLineEdit to a custom slot programatically. I know how to do the connection by using Qt Designer and doing the connection with graphical interface but I would like to do it programmatically so I can…
fs_tigre
  • 10,650
  • 13
  • 73
  • 146
13
votes
1 answer

PyQt5: How can I connect a QPushButton to a slot?

Okay, so pretty much every tutorial/understandable-written-in-human-language-documentation is for PyQt4. But, PyQt5 changed how the whole 'connect button to a slot' works, and I still can't figure it out how to do it. I did a quick gui in…
JJS
  • 1,086
  • 2
  • 13
  • 16
12
votes
5 answers

Using any c++ function as a Qt slot

Is there a way to use any C++ function as a Qt slot, without having its class inheriting from QWidget?
Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
12
votes
5 answers

Is it possible to create a signal for when a QTreeWidgetItem checkbox is toggled?

I've created a checkbox that's also a QTreeWidgetItem using the code below. //Populate list QTreeWidgetItem *program = createCheckedTreeItem(QString::fromStdString(itr->first), true); treePrograms->addTopLevelItem(program); QTreeWidgetItem*…
Robert Whitley
  • 1,051
  • 5
  • 14
  • 28
12
votes
4 answers

Qt signals & inheritance question

I am relatively new to programming with Qt and had a question. Short version: How do I inherit signals defined in superclasses? I am trying to subclass someone else's nicely made QTWidgets to change some of the default behavior: //Plot3D is a…
Pete
  • 2,336
  • 2
  • 16
  • 23
12
votes
2 answers

Signals vs Signals2

I have application that may benefit from using one of boost's signals libraries over a homegrown solution. The application is multithreaded but the part that does the signal processing is single threaded. Is there any reason to prefer Boost.Signals2…
deft_code
  • 57,255
  • 29
  • 141
  • 224