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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Trusted Contributor
lyon819
Posts: 246
Registered: ‎08-19-2010
My Carrier: TT
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
Please use plain text.
BlackBerry Development Advisor
mwoolley
Posts: 168
Registered: ‎06-25-2010
My Carrier: Vodafone

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!

 

 

Please use plain text.
Trusted Contributor
lyon819
Posts: 246
Registered: ‎08-19-2010
My Carrier: TT

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
Please use plain text.