What is the difference between a slot and a method in Qt?

scdmb

What is the difference between a slot (a method declared in slots section) and a method in Qt (a method declared with Q_INVOKABLE keyword)? They both can be invoked using QMetaObject::invokeMethod, they are both accepted when connecting to a slot using SLOT macro, however when getting type of metamethod it can be returned either QMetaMethod::Method or QMetaMethod::Slot, so it seems that there is some difference for Qt?

Kuba hasn't forgotten Monica

The only difference is whether the method is listed as a slot or as not-a-slot in the class's metadata. In both Qt 4 and Qt 5, connection to either a slot or an invokable succeeds:

#include <QObject>
struct Test : public QObject {
  Q_SLOT void slot() {}
  Q_INVOKABLE void invokable() {}
  Q_OBJECT
};

int main() {
  Test test;
  auto c1 = QObject::connect(&test, SIGNAL(destroyed(QObject*)), &test, SLOT(slot()));
  auto c2 = QObject::connect(&test, SIGNAL(destroyed(QObject*)), &test, SLOT(invokable()));
  Q_ASSERT(c1);
  Q_ASSERT(c2);
}
#include "main.moc"

It's up to the user to decide how the difference between a slot and an invokable is interpreted. E.g. if you're exposing the slot list to the user in some way, you won't be exposing the invokable method list unless you choose to do so.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

What is the difference between `git diff` and `git difftool`?

来自分类Dev

Ruby - What is the difference between intern and to_sym

来自分类Dev

What's the difference between Yii 2 advanced application and basic?

来自分类Dev

What is the difference between a method and a proc object?

来自分类Dev

What is the difference between diff and diff=astextplain?

来自分类Dev

what is the difference between pdo and fdo in windows device drivers?

来自分类Dev

What is the difference between LALR and LR parsing?

来自分类Dev

What is the difference between type conversion and type assertion?

来自分类Dev

What was the difference between WSDL & Mex Endpoint in WCF

来自分类Dev

What is the difference between async([](){}) and thread([](){}).detach()?

来自分类Dev

What is the best way to communicate between two windows in Qt

来自分类Dev

What is the difference between getContext('webgl') vs getContext('3d')?

来自分类Dev

What's the difference between @observable and @published in polymer.dart?

来自分类Dev

What is the difference between DOMXPath::evaluate and DOMXPath::query?

来自分类Dev

What is the difference between Command + CommandHandler and Service?

来自分类Dev

what is the difference between Redirect:to() and Redirect::route()?

来自分类Dev

What's the difference between gets and scanf?

来自分类Dev

What is the difference between x^2 and I(x^2) in R?

来自分类Dev

What is difference between lists, arrays, and tuples in F#?

来自分类Dev

what is the difference between using or not Spring Beans?

来自分类Dev

What is the difference between Invariants and Validation Rules?

来自分类Dev

What is the difference between Lexical grammar and Syntactic grammar?

来自分类Dev

What is the difference between these two ruby functions?

来自分类Dev

What is the difference between Genetic and Cellular Genetic algorithm

来自分类Dev

What is the difference between isomorphic-fetch and fetch?

来自分类Dev

what's the difference between is not null and <>' '

来自分类Dev

What is the difference between (a+b)* and (a*b*)*?

来自分类Dev

What is the difference between /opt and /usr/local?

来自分类Dev

Qt中SLOT的类型是什么?

Related 相关文章

  1. 1

    What is the difference between `git diff` and `git difftool`?

  2. 2

    Ruby - What is the difference between intern and to_sym

  3. 3

    What's the difference between Yii 2 advanced application and basic?

  4. 4

    What is the difference between a method and a proc object?

  5. 5

    What is the difference between diff and diff=astextplain?

  6. 6

    what is the difference between pdo and fdo in windows device drivers?

  7. 7

    What is the difference between LALR and LR parsing?

  8. 8

    What is the difference between type conversion and type assertion?

  9. 9

    What was the difference between WSDL & Mex Endpoint in WCF

  10. 10

    What is the difference between async([](){}) and thread([](){}).detach()?

  11. 11

    What is the best way to communicate between two windows in Qt

  12. 12

    What is the difference between getContext('webgl') vs getContext('3d')?

  13. 13

    What's the difference between @observable and @published in polymer.dart?

  14. 14

    What is the difference between DOMXPath::evaluate and DOMXPath::query?

  15. 15

    What is the difference between Command + CommandHandler and Service?

  16. 16

    what is the difference between Redirect:to() and Redirect::route()?

  17. 17

    What's the difference between gets and scanf?

  18. 18

    What is the difference between x^2 and I(x^2) in R?

  19. 19

    What is difference between lists, arrays, and tuples in F#?

  20. 20

    what is the difference between using or not Spring Beans?

  21. 21

    What is the difference between Invariants and Validation Rules?

  22. 22

    What is the difference between Lexical grammar and Syntactic grammar?

  23. 23

    What is the difference between these two ruby functions?

  24. 24

    What is the difference between Genetic and Cellular Genetic algorithm

  25. 25

    What is the difference between isomorphic-fetch and fetch?

  26. 26

    what's the difference between is not null and <>' '

  27. 27

    What is the difference between (a+b)* and (a*b*)*?

  28. 28

    What is the difference between /opt and /usr/local?

  29. 29

    Qt中SLOT的类型是什么?

热门标签

归档