[Qt-creator] Find references of virtual functions?

Konstantin Tokarev annulen at yandex.ru
Sat Sep 12 00:51:11 CEST 2020



12.09.2020, 01:30, "Giuseppe D'Angelo via Qt-creator" <qt-creator at qt-project.org>:
> Il 11/09/20 22:59, Murphy, Sean ha scritto:
>>  Is there any way in Qt Creator to only show me the places where Grandchild::foo() is called? Right now, I'm finding that even if I go to grandchild.cpp, put my cursor on void Grandchild::foo(), and then select "Find Reference to Symbol Under Cursor", it shows me every instance of EVERY foo() called anywhere in the program, including the declarations/definitions of Abstract::foo(), Base::foo() and Child::foo(), which I don't care about at the moment.
>
> By "every foo()" do you mean even the ones completely unrelated to your
> class hierarchy, or all the foo() in the hierarchy?
>
> Anyhow, given it's a virtual, how can you know at compile time if you're
> calling GrandChild::foo() or not?
>
> Abstract *blah = getFoo();
> blah->foo(); // might call Grandchild::foo(), or not

FWIW, there are at least 3 cases when it is certainly known at compile time which overload is called:

1) if object is referenced by value:
  
  Grandchild blah;
  blah.foo();

2) fully qualified method call:

  Grandchild *blah = getFoo();
  blah->Grandchild::foo(); // or Base::foo() etc.

3) when foo() is final in Grandchild:
  
  Grandchild *blah = getFoo();
  blah->foo();


-- 
Regards,
Konstantin


More information about the Qt-creator mailing list