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
Developer
dbigham
Posts: 469
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA
Accepted Solution

error: 'QmlDocument' was not declared in this scope

[ Edited ]

I'm following along the following:

 

https://developer.blackberry.com/cascades/documentation/ui/integrating_cpp_qml/index.html

 

And have added the following code to main.cpp:

 

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>

#include "app.hpp"

using ::bb::cascades::Application;

int main(int argc, char **argv)
{
    Application app(argc, argv);

    QmlDocument *qml = QmlDocument::create("main.qml");
    AbstractPane *root = qml->createRootNode();
    Application::setScene(root);

    return Application::exec();
}

 

When compiling, I get the error:

 

error: 'QmlDocument' was not declared in this scope
Please use plain text.
Developer
HuXu77
Posts: 195
Registered: ‎02-10-2011
My Device: Playbook 16GB and Z10
My Carrier: Verizon

Re: error: 'QmlDocument' was not declared in this scope

[ Edited ]

Your namespace looks weird.

using bb::cascades;

Try that.

 

Edit: Also if I was you I would just create a new project and select HelloCasades as a template.  That will get you running lots quicker than trying to do it from scratch.

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Please use plain text.
Developer
dbigham
Posts: 469
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: error: 'QmlDocument' was not declared in this scope

Ughh. So simple, I feel silly for not noticing that.

 

Thanks.

 

A secondary issue was that I was confusing main.cpp with app.cpp, and the code I was using belongs in app.cpp. If I hadn't made that mistake, I wouldn't have had the issue at all since the sample code for app.cpp contains the proper using statement.

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: error: 'QmlDocument' was not declared in this scope

[ Edited ]

Expanding on HuXu77's answer in case you're not familiar with namespaces or "using":

 

using bb::cascades  or  using ::bb::cascades will work: this says "expose all names in bb::cascades as if it's in the global namespace".  So you can refer to bb::cascades::QmlDocument without scoping it (provided you don't have a ::QmlDocument)

 

Some people prefer to promote only the classes they intend to be using.  In your case two classes:

 

using bb::cascades::Application;

using bb::cascades::QmlDocument;

This way you can have a my::Image class and bb::cascades::Image and require explicitly specifying each one in the code -- the compiler will tell you if you use Image without specifying which one.

 

Some people prefer to scope each use, but that quickly becomes cumbersome if it's more than one or two places in the file:

  bb::cascades::QmlDocument* qml = bb::cascades::QmlDocument::create().load(....);

 

For cascades, as with std, "using" everything in the namespace is reasonable because if you have a cascades project you typicallly won't have any names that collide.

 

Aside: This should be done in your cpp files, not in your .h files.  Otherwise you're forcing everyone using your .h files to be using the cascades namespace, which can lead to errors not detected by the compiler.

 

Stuart

Please use plain text.