[Qt-creator] How to match function invocation and definition?

Nikolai Kosjar nikolai.kosjar at digia.com
Wed Nov 6 16:26:48 CET 2013


Hi!

> Now I can get a declaration string for a function from cmpDecl.  I think
> this can be used to match the declarations in the .h files, but may not
> be the best idea. So here I want to ask for some other solutions.

You don't need the declaration as a string. Since you did a look up, the 
resulting symbols represent the possible declarations. E.g. check your 
"d" symbol (d->fileName(), d->line(), d->column(), d->type()).

If you need the matching definition for your declaration (recommended, 
see below), use SymbolFinder::findMatchingDefinition().

> (1)As I was told previously, I can get the function/class list by the
> following code:
>      CppTools::Internal::CppLocatorData*locD =
> (CppTools::Internal::CppLocatorData*)
> ExtensionSystem::PluginManager::getObjectByClassName("CppTools::Internal::CppLocatorData");
>      QList<CppTools::ModelItemInfo>f = locD->functions();
>      QList<CppTools::ModelItemInfo>c = locD->classes();
>
> So how to search a specific declaration in the list ?

ModelItemInfo has fileName, line and column members. You could compare 
these to the fileName, line and column of the symbol/function returned 
by SymbolFinder::findMatchingDefinition().

Note that the locator data provides only information about definitions, 
e.g. function definitions, not their declarations. So if you have a 
symbol you want to match with the function from the locator data, make 
sure its origin is a function definition.

> (2) I also note that the FullySpecifiedType have == operator, will this
> help me?

No since LocatorData does not provide these kind of types.


Nikolai



More information about the Qt-creator mailing list