Ghorm
Ghorm

Reputation: 95

What is the difference between two connect styles in Qt?

We can use old syntax, like this

connect(sender, SIGNAL(valueChanged(QString, QString)), receiver, SLOT(updateValue(QString));

And new one, like this

connect(sender, &Sender::valueChanged, receiver, &Receiver::updateValue);

New syntax allows us to see errors with connect on compile time, which is a plus, but is there another differences? I can recall I saw something about it, but can't recall or find it.

Upvotes: 0

Views: 138

Answers (1)

Alexander Zolkin
Alexander Zolkin

Reputation: 194

Thanks to @chehrlic for articles about this question. In summary, differences between these two approaches are:

  1. Compile-time check. You can't compile application until all connect() will be used correctly.
  2. Arguments automatic type conversion. New syntax allow us not to worry about implicit conversions, e.g. QVariant can be used as QString.
  3. Usage of С++ lambda expressions. You can connect lambda expressions, if you wish so.
  4. You can use not only slots to be receivers of the signals, but any function or functor.

Upvotes: 1

Related Questions