Important: Please read the Qt Code of Conduct -

What is the differnce between Signal and slot?

  • Hi all,
    I have a doubt about signal and slot.Whether the signal has definition or declaration only.and what is slot?.Please suggest me soon.


  • @Sunmuk said:

    Please suggest me soon.

    I suggest to read soon this page :)

  • Hi,
    I referred the link mentioned previously.I am clear now with the concept like "Whether signal has implementation?".But still now confused with the signal.
    code snippet is
    void ItemAdded( Item item);

    My question is
    1.How this signal is emitted?
    2.Why signal has the argument?
    3.What is the relation between signal and its parameter?

  • Hi,

    1. how explained in the article, a signal is emitted using the emit keyword or the Q_EMIT macro
    emit <signal_name>(<parameters_list>);
    Q_EMIT <signal_name>(<parameters_list>);
    1. Sometimes you need to signal what is changed and not only that something is changed

    2. the signal is the notification that something happened, parameters are details about the event

  • Signals are declaration only. Slots provide the code that shall be executed when the signal gets emitted.

    When you emit a signal, then all assigned slots are executed with the arguments of the signal.

  • @s.frings74 said:

    Signals are declaration only.

    Even though other part of explanation is correct above is wrong.
    There is no magic and signal is actually a function.
    User does not provide its implementation though.
    It is automatically generated during mocing.
    You can check look at generated code in the generated moc_*.cpp file.

  • @mcosta

Log in to reply