Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

New Developer
Posts: 51
Registered: ‎03-10-2012
My Device: PlayBook
My Carrier: n/a

Any way to add missing header files to a .h?



I come from .Net development, and I'm quite new to C++. Sometimes I use objects that are not included in the "include" regions at the header of the cpp file. For example, to use CCPoint, I need to include a header, but sometimes it's tricky to know what is the necessary header.


Is there any way to add the headers automatically? In .Net we have the "resolve namespace" feature that adds the necessary "usings" at the top of the c# classes.





Posts: 62
Registered: ‎03-31-2012
My Device: Playbook
My Carrier: None

Re: Any way to add missing header files to a .h?

I don't know such a feature. In C/C++ it's also difficult to do such things, cause every file could have the definition of many classes with defines used for definition of classnames. That's the advantage and disadvantage of a precompiler. So the only way I know is to use a search-engine at the internet.

Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Any way to add missing header files to a .h?

Short answer:



Mid-sized answer:

By convention, most classes are defined in a .h file of the same name.

So if you need ListView you will #include <bb/cascades/ListView>, and if you need QPoint you will #include <QPoint>.

Find an example of something in the right subsystem and you'll know what to include.


Other standard types are well documented everywhere, including the linux command "man <thing>". The documentation should tell you what to include, and you'll quickly learn them.


Long answer:

This is a feature you don't want.   #include in C++ is not the same as #import in other languages.  In C++, each cpp file is compiled separately, and each #include effectively inserts the code inline.   This leads to two issues:

1)  (typically not an issue any more)  Lots of includes means lots of file I/O and compile time per cpp file

2)  Cascaded includes affects incremental build times.  If a.h includes b.h includes c.h includes... then everything that includes a.h will be recompiled if you touch z.h.


Occasionally someone has defined include files that must be included in a particular order.


Often C++ coders like to see system include files first, 3rd party include files second, followed by their own.


So here's the usual approach:

- .h files should refer to classes by reference or pointer where possible, and provide a forward declaration,


      namespace bb


          namespace cascades


               class QmlDocument;



- .cpp files that actually require the full definition should #include the definition.

- exception is small well encapsulated classes designed to be passed by value, e.g. QPoint and QString.


Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Any way to add missing header files to a .h?

I take back my "no", but bear in mind the rest of my comments.


Let's say you have C++ code like:

    QmlDocument* qml = QmlDocument::create("main.qml");

and you haven't added the include file for it.


In Momentics, click on QmlDocument, then either:

   Source/Add Include


   <right-mouse context menu>/Source/Add Include




This will add the required include for this class.