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
9
votes
1 answer

How to find out from the slot which signal has called this slot?

I mean if I have many different signals which are connected to the same slot. I saw this question but can't understand the link in the answer. Can you give me simple example?
ratojakuf
  • 708
  • 1
  • 11
  • 21
9
votes
2 answers

How to create dynamic signals and slots in Qt?

The signal/slot mechanism in Qt, is a static mechanism. The classes have to be preprocessed by the moc compiler. Now I want to create signals and slots dynamically at run-time. I already have a working solution, but it feels to me like a hack,…
Kurt Pattyn
  • 2,758
  • 2
  • 30
  • 42
9
votes
1 answer

PyQt5 Signals and Slots 'QObject has no attribute' error

I have been trying to find a way to update the GUI thread from a Python thread outside of main. The PyQt5 docs on sourceforge have good instructions on how to do this. But I still can't get things to work. Is there a good way to explain the…
ADB
  • 1,210
  • 4
  • 15
  • 23
9
votes
1 answer

Qt: Return value of signal works, why is the official doc saying it is impossible / forbidden?

Qt documentation says, return values of signals are not possible: 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). Related SO questions: Can Qt…
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
8
votes
3 answers

Qt multiple inheritance and signals

I'm having a problem with QT regarding multiple enheritance because of QObject. I know that a lot of others have the same problems but I don't know how I should fix it. class NavigatableItem : public QObject { Q_OBJECT signals: void…
RvdK
  • 19,580
  • 4
  • 64
  • 107
8
votes
3 answers

Difference between emit and emit()

In Qt, both of them are valid, and behave the same: emit someSignal(value); vs emit(someSignal(value)); Is there any difference?
otisonoza
  • 1,334
  • 2
  • 14
  • 32
8
votes
2 answers

QObject: Missing vtable link error

I know the question have been asked tons of times but I can't find the solution here nor in google. Here's my header file #ifndef MAINCONTROLLER_H #define MAINCONTROLLER_H #include #include #include #include…
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
7
votes
4 answers

Is it OK to use `waitForReadyRead()` instead of creating a slot for `readyRead()` signal?

Writing a cross platform app using Qt (including Windows with MinGW). For reading data from SSL socket, I am creating a separate thread. This thread is there for historical reason, because earlier the app was written using C socket/ssl/crypto…
iammilind
  • 68,093
  • 33
  • 169
  • 336
7
votes
2 answers

How to use the argument of a Signal in QML StateMachine during SignalTransition

I have a C++ class and I made it possible to be able to create it in QML. Then I have a signal in QML which has an argument representing this object. I am using the QtQml.StateMachine and I am catching triggered signals with SignalTransition. I want…
Silex
  • 2,583
  • 3
  • 35
  • 59
7
votes
3 answers

PyQt - get list of all checked in QTreeWidget

I am building a simple application to open up a folder of data and plot that data. Importing the data updates a QTreeWidget that shows which signals are available to plot. Ex: The QTreeWidget is populated after the data is imported using: def…
dan_g
  • 2,712
  • 5
  • 25
  • 44
7
votes
2 answers

does the slot function in Qt run on another thread?

In the following function, manager will emit finished(QNetworkReply*) signal, then the slot function getCategories(QNetworkReply*) will be called. void getCategories() { connect(manager, SIGNAL(finished(QNetworkReply*)), this,…
stamaimer
  • 6,227
  • 5
  • 34
  • 55
7
votes
5 answers

How to detect Windows shutdown or logoff in Qt

I am porting a Linux app to Windows written in Qt. The application needs to save some settings before closing. On Linux, we can do that by signal handlers for SIGTERM etc. How can I implement the same on Windows.
adnan kamili
  • 8,967
  • 7
  • 65
  • 125
6
votes
1 answer

Why a new signal for socket::readyRead() is executed, even when its earlier slot is still processing?

According to following post an emitted signal is served, only once the currently executing slot completes. Wait for a SLOT to finish the execution with Qt I have a client-server communication app based on ssl socket, which is single…
iammilind
  • 68,093
  • 33
  • 169
  • 336
6
votes
1 answer

Signal to Slot in QT Creator, where is connect() function?

In QT Creator, design mode, I right-click on a widget and select "Go to slot" and it creates a slot function for one of the widget's signals. I would have thought that this would have generated a connect() function to create this connection,…
6
votes
4 answers

Qt Signal/Slots sending a complete structure

I am attempting to send a structure via signals/slots between two threads, my signals/slots are connected properly and I have been able to send QStrings containing parts of my data but now I need to send the whole thing and Structures seem most…
Harry de winton
  • 969
  • 15
  • 23
1 2
3
33 34