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

Send a signal when a USB serial cable is unplugged

Is there a way to send a signal, or any other way to tell if a USB serial cable is unplugged, using Qt?
Jared Price
  • 5,217
  • 7
  • 44
  • 74
4
votes
2 answers

QTableView, QStandardItemModel and Signals

I have a QTableView, populated with a QStandardItemModel. I update the model frequently over network and the model is also updated by user directly via the QTableView. Now I like to call a method when the user is changing some data, so i…
nfo
  • 637
  • 2
  • 6
  • 19
4
votes
2 answers

How to connect multiple PyQt Signals w/ variable arguments to single slot/signal repeater

Example: class MyClass(QObject): signal_1 = pyqtSignal(str, int) signal_2 = pyqtSignal(int, int) signal_3 = pyqtSignal(str, int, int) Let's say each of these signals is connected elsewhere to perform various functions, however, there's…
Connor Spangler
  • 805
  • 2
  • 12
  • 29
4
votes
1 answer

How to connect to a column delegate's signal

I have created a working PushButton Delegate for a QTableView. When the button is pressed, it will emit a buttonClicked signal (and also print to show that it is working. I have set the pushbutton delegate as the item delegate for the column 1 (see…
Drew
  • 517
  • 5
  • 16
4
votes
1 answer

QT: Connect signals to slots with move semantics

Ok, i have something like this: void EmailReceiverThread::foreachEmailAccount(ConfigEmailAccount account) { Email email; EmailReader emailReader(account); while (emailReader.pollEmail(email)) { writeEmailToDatabase(email); …
amchacon
  • 1,891
  • 1
  • 18
  • 29
4
votes
1 answer

Qt signal and slots: are reference arguments copied?

In qt framework, most library signals and slots use pointers as parameters. I was wondering, If I create a signal-slot "structure" that takes a reference as the parameter instead of the pointer, will the whole parameter be copied, or just 4 bytes…
Łukasz Przeniosło
  • 2,725
  • 5
  • 38
  • 74
4
votes
3 answers

Qt C++ connect QPushButton click

I have just started developing using QtGUI and I have checked out some tutorials and documentation, and by what I've read this should work. #define CONNECT QObject::connect void test(); QPushButton *lpTestBtn; int main(int argc, char *argv[]) { …
user2920222
  • 197
  • 1
  • 2
  • 8
4
votes
2 answers

Qt - Is there a way to emit a signal when a particular key is typed?

I am working on a project in Qt 4.7 where a have a QListWidget which needs to perform a certain function when an item from the list is selected. The particular function isn't important here, so for this example let's say it is to print the value to…
thnkwthprtls
  • 3,287
  • 11
  • 42
  • 63
4
votes
3 answers

Qt: How to wait for multiple signals?

I'm developing a GUI test library of sorts using PySide and Qt. So far it works quite nicely when the test case requires waiting for only one condition to happen (such as a signal or a timeout), but my problem is having to wait for multiple…
Teemu Karimerto
  • 395
  • 5
  • 12
4
votes
2 answers

Passing structure to signal in Qt

I want to send a structure with a signal in Qt. How can I do this? I know how to send integers, strings, Images etc with a signal but getting confused with the structure part. I read some posts and found out about Q_DECLARE_METATYPE() but I am not…
Sid411
  • 703
  • 2
  • 9
  • 25
4
votes
1 answer

Disconnect and later reconnect a Qt signal

Is there a way to disconnect a Qt signal only temporarily, but store a list of the objects connected to it, so the signal can later be reconnected to them?
sashoalm
  • 75,001
  • 122
  • 434
  • 781
3
votes
2 answers

Get text from QPushButton in PyQt

I'm trying to create a simple keyboard from list of QtGui.QPushButton objects. class XKeyboard(QtGui.QWidget): '''Special virtual keyboard for any language.''' def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) …
ghostmansd
  • 3,285
  • 5
  • 30
  • 44
3
votes
1 answer

Qt Custom Slots

Why doesn't the slot Reset() work? I want the button "reset" to reset the value of the sider to zero. class MySlider : public QSlider { public: MySlider(Qt::Orientation orientation, QWidget *parent = 0) : QSlider(orientation parent){} …
Geore Shg
  • 1,299
  • 5
  • 23
  • 38
3
votes
2 answers

Changed Properties do not trigger signal

For a subclass of QObject I'd like to define a property. On change, a signal should be emitted. According to the documentation, something like this: p = Property(int, _get_p, _set_p, notify=p_changed) should work, but the signal is not emitted by…
zeeMonkeez
  • 5,057
  • 3
  • 33
  • 56
3
votes
1 answer

How do I setup Signals and Slots in PyQt with QThreads in both directions?

This is a followup-question based on ekhumoro's answers here and here. I thought to understand, that when a slot is correctly defined with pyqtSlot and assigned to QThread (e.g. with moveToThread()), it will be executed in this QThread and not the…
Skandix
  • 1,916
  • 6
  • 27
  • 36