Welcome!

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

Reply
Contributor
polov
Posts: 13
Registered: ‎01-13-2013
My Device: BlackBerry Z10
Accepted Solution

unknown ArrayDataModel

[ Edited ]

Hi, I am new to cascades and native development and have problems with development.

 

I wanted to use ArrayDataModel in my class but compiler do not know anything about ArrayDataModel:

 

#include <bb/cascades/ArrayDataModel>

..

private:

ArrayDataModel *model;

 

Compiler:

qcc -Vgcc_ntox86 -c -Wc,-include -Wc,o-g/.obj/ListTest -Wno-psabi -lang-c++ -fstack-protector-strong -g -Wno-psabi -Wall -W -D_REENTRANT -DQT_NO_IMPORT_QT47_QML -DQ_OS_BLACKBERRY -DQT_DECLARATIVE_DEBUG -DQT_DECLARATIVE_LIB -DQT_CORE_LIB -DQT_SHARED -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/share/qt4/mkspecs/blackberry-x86-qcc -I../../ListTest -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/qt4/QtCore -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/qt4/QtDeclarative -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/qt4 -I../src -Io-g/.moc -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include -I/Applications/bbndk/target_10_0_9_1673/qnx6/usr/include/freetype2 -I. -o o-g/.obj/ListTest.o ../src/ListTest.cpp In file included from ../src/ListTest.cpp:8:0: ../src/Model.hpp:21:2: error: 'ArrayDataModel' does not name a type

 

../src/Model.hpp:29:2: error: 'ArrayDataModel' does not name a type

 

Can anyone point me to the solution of the problem please?

Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: unknown ArrayDataModel

[ Edited ]

Try the following steps:

1) Remove #include <bb/cascades/ArrayDataModel> from .h file

2) In .h file forward-declare the class like this:

namespace bb
{
  namespace cascades
  {
    class ArrayDataModel;
  }
}

 

3)
Use fully-qualified names in header files:

private:
  bb::cascades::ArrayDataModel *model;

 

4) In C++ file add:

#include <bb/cascades/ArrayDataModel>

using namespace bb::cascades;


Andrey Fidrya, @zmeyc on twitter
Contributor
polov
Posts: 13
Registered: ‎01-13-2013
My Device: BlackBerry Z10

Re: unknown ArrayDataModel

Thanks a lot. It worked.

I have just one question - why it is not working just with import?

Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: unknown ArrayDataModel

Cascades classes reside in bb::cascades namespace. So it would work if you used fully-qualified name or added "using namespace bb::cascades". But the steps above is the recommended way to design C++ classes.

 

It's not recommended to call "using namespace" in .h files: namespaces exist to resolve potential naming conflicts and this will pollute namespace of every .cpp file which includes such header file.

 

#include directive in C++ simply inserts the text of specified file during preprocessing stage. So you can include things in ".h" files, but this will slow down the compilation as every .cpp file which uses the header will get a copy of all included headers even if it doesn't need them.

 

So it's generally recommended to keep the number of #include-s minimal and to forward-declare classes in .h files.

 #include them only in .cpp where they are used.

 

 

Complete class definition is required when the class is instantiated, for example:

 

SomeClass t;   // #include is required

 

When a pointer or a reference is declared, forward declaration is enough:

 

SomeClass *t; // no need to #include the header

SomeClass &t; //  no need to #include the header

 

t = new SomeClass; // instantiation, #include is required

 

Complete class definition is also required when inheriting from classes:

 

class X: public Y  // #include <Y> is required

{ ... }

 


Andrey Fidrya, @zmeyc on twitter