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

Qt code does not compile when i try to connect one signal to a slot

I'm new to Qt. I'm trying to implement a really simple calculator program. Just trying to put a button, and when its clicked, i want it to print "Hello, World!" to the next lineEdit. It is working fine when i have only one button, but when I add the…
arikan
  • 893
  • 9
  • 18
6
votes
1 answer

QMetaObject::invokeMethod doesn't find methods with parameters

This is a follow up of QMetaObject::invokeMethod doesn't find the method. Invoking a method without paramters works. But extending the previous question to methods with parameters brings me back to failure again. See the following example script in…
NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
6
votes
2 answers

Q_ENUMS are "undefined" in QML?

Enums are not working out for me. I have registered them with Q_ENUMS() I did not forget the Q_OBJECT macro the type is registered using qmlRegisterType() the module is imported in QML In short, everything is "by-the-book" but for some reason I…
user2341104
6
votes
1 answer

How to pass a QString to a Qt slot from a QMenu via QSignalMapper or otherwise

I have a QMenu with many submenus. These are dynamically created i.e. the names menus come from a db and created in a loop. Now i wanted to fire the same slot triggered() or similar when a menu is clicked, but i needed the QString menu name to be…
fkl
  • 5,412
  • 4
  • 28
  • 68
6
votes
2 answers

QML signal executed twice

I'm new in QML and QML signals and I'm having this silly problem that I'm not being able to resolve by myself. I'm triggering an onTouch signal and is executing twice, generating a double response that crashes my app. Here's my QML…
mariomunera
  • 323
  • 1
  • 4
  • 18
5
votes
2 answers

QSpinBox and QDoubleSpinBox do not call method on valueChanged

All i want to do is call a method when the value of a qspinbox and a doublespinbox are changed. I do not need the actual value from the spinbox being changed, i just want it to trigger the calling of another method. Why does the code below not error…
JokerMartini
  • 5,674
  • 9
  • 83
  • 193
5
votes
1 answer

How can I send a python dictionary to a QML interface with a Signal?

I want to send dictionaries, containing data that I need to use to dynamically create qml objects, from a PySide2 class to a QML interface and since I need to do it in response to certain events, I need to use signals and slots. Since I've just…
Lando1784
  • 426
  • 1
  • 4
  • 12
5
votes
1 answer

Optional Signal Arguments

I have a function which has default keyword arguments. I'm having trouble implementing this as I keep getting an error that if my signal has two arguments then I need to pass both arguments. Is there any way around this? class Controller(QWidget): …
aoh
  • 1,090
  • 2
  • 13
  • 25
5
votes
1 answer

Qt - Q_PROPERTY's NOTIFY signal not emited about MEMBER change

I have a private class member variable status and i want to emit a signal with its value everytime it changes. Therefore I use Q_PROPERTY and specify a signal with NOTIFY: #ifndef CAMERACONTROL_H #define CAMERACONTROL_H #include #include…
goulashsoup
  • 2,639
  • 2
  • 34
  • 60
5
votes
2 answers

Passing parameters from C++ to QML

I want to pass some parameters from C++ to QML, so that QML can do something with them. Somewhat like this: void MyClass::myCplusplusFunction(int i, int j) { emit mySignal(i, j); } In QML, every time that mySignal(i, j) is emitted, I want to…
Don Joe
  • 274
  • 4
  • 13
5
votes
3 answers

can time.sleep(secs) suspend QNetworkAccessManager does request asynchronously?

QNetworkAccessManager can do requests asynchronously, and time.sleep(secs) can suspend the execution for the given number of seconds. I was confused by the code below. Is t2 here always greater than 10 seconds? Without using time.sleep(secs) in the…
iMath
  • 2,326
  • 2
  • 43
  • 75
5
votes
3 answers

Qt #define "signals" clashes with GStreamer (gst)

Qt, which seems to name everything else with an initial Q, does this: #define signals signals in qobjectdefs.h. However, GStream, not naturally, does not imagine signals to be a reserved word and does this struct _GDBusInterfaceInfo { /*< public…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
5
votes
3 answers

QLineEdit editingFinished signal twice when changing focus?

I've found a few similar questions on this but these appear to refer to cases where a message box is used in the slot handler. In my case I am a bit stuck as I am getting the editFinished signal twice even when my slot handler is doing nothing. For…
Toby
  • 131
  • 2
  • 8
5
votes
2 answers

Qt signal lambda causes shared_ptr leak?

I have the following code: #include #include #include #include class Document { public: Document() { qDebug("Document"); } ~Document() { qDebug("~Document"); …
paulm
  • 5,629
  • 7
  • 47
  • 70
5
votes
1 answer

Is the connect() call thread safe in Qt?

I have two QObjects A and B living in separate QThreads. A will emit a signal while B has a matching slot. I want to use connect() to connect A's signal to B's slot. So the question is, is the connect() call thread safe? Does it matter in which of…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95