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
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
Accepted Solution

How to combine bb::cascades and bb::device

Purpose:

Want to get screen height and width for .qml.

 

Problme:

When I try to get screen width, .qml code shows error.

or

When I try to use .qml, screen properties shows error.

 

code:

using namespace bb::cascades;
using namespace bb::device;??

 

int main(int argc, char **argv)
{
// this is where the server is started etc
Application app(argc, argv);

// localization support
QTranslator translator;
QString locale_string = QLocale().name();
QString filename =****
if (translator.load(filename, "app/native/qm")) {
app.installTranslator( &translator );
}

// Load the UI description from main.qml
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(&app);

DisplayInfo display;
int width = display.pixelSize().width();
int height = display.pixelSize().height();

 

Does anyone know how to use device and cascade in one project.

 

Thanks your attention.

 

-Fight with BB10
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: How to combine bb::cascades and bb::device

Hi

 

I'm not clear exactly where you are seeing errors.

 

However the following code works for me:

 

// Default empty project template
#include "Test.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/device/DisplayInfo.hpp>

using namespace bb::cascades;
using namespace bb::device;

Test::Test(bb::cascades::Application *app)
: QObject(app)
{

    DisplayInfo display;
    qDebug() << "XXXX display id is " << display.displayId();
    qDebug() << "XXXX display name is " << display.displayName();
    qDebug() << "XXXX display size is " << display.pixelSize().width() << ", " << display.pixelSize().height();

    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app->setScene(root);
}

 Make sure you add the following line to your project's .pro file 

 

LIBS += -lbbdevice

 

per the documentation: http://developer/cascades/reference/bb__device__displayinfo.html

 

Hope this helps!

 

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.

Re: How to combine bb::cascades and bb::device

LIBS += -lbbdevice is my issue. 

 

After I add the LIBS += -lbbdevice under HEADERS += ../src/*.hpp ../src/*.h for the .pro file.

No warning comes out.

 

Thank you a lot, Solved it.

 

 

 

 

-Fight with BB10