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
babakar
Posts: 770
Registered: ‎05-29-2012
My Device: see later
Accepted Solution

Blackberry OS10 simple questions

I have this code

 

/*
 * Copyright (c) 2011-2013 BlackBerry Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>
#include <bb/cascades/Container>

using namespace bb::cascades;

ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
    // This is only available in Debug builds
    Q_ASSERT(res);
    // Since the variable is not used in the app, this is added to avoid a
    // compiler warning
    Q_UNUSED(res);

    // initial load
    onSystemLanguageChanged();

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    Container *container = new Container();

    Image image = Image(QUrl("asset:///images/myimage.png"));
    container->add(image);

       root->setContent(container);
    // Set created root object as the application scene
    app->setScene(root);
}

void ApplicationUI::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("MySecondApp_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

 

 

I have errors at lines container->add(image);

       root->setContent(container);

How can I fix it? Also how can i arrange pictures in a container vertically, not horizontally.

 

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Blackberry OS10 simple questions

[ Edited ]

Are you include Image  ?

#include <bb/cascades/Image>
The Container default layout is StackLayout with ToptoBottom orientation. So is vertically arranged


If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
babakar
Posts: 770
Registered: ‎05-29-2012
My Device: see later

Re: Blackberry OS10 simple questions

even if i include that, i still get error at the following

 

   container->add(image);

       root->setContent(container);

 

Multiple markers at this line
    - candidate is:
    - no matching function for call to
     'bb::cascades::Container::add(bb::cascades::Image&)'

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Blackberry OS10 simple questions

[ Edited ]

Change this

container->add(image)

to this

container->add(&image)


If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Blackberry OS10 simple questions

the UI component is ImageView, not Image.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Blackberry OS10 simple questions

Yop, i overlooked this :Wacko:



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
babakar
Posts: 770
Registered: ‎05-29-2012
My Device: see later

Re: Blackberry OS10 simple questions

that doesnt solve it either

 

  Image image = Image(QUrl("asset:///images/myimage.png"));
    ImageView *object1 = new ImageView();

        object1->setImage(image);
    container->add(object1);

       root->setContent(container);

this solves it, i do imageview..i add it to imageview and then add it to container.

however i get error this time at         root->setContent(container);

 

 

Multiple markers at this line
    - 'class bb::cascades::AbstractPane' has no member named
     'setContent'
    - Line breakpoint: applicationui.cpp [line: 61]

Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: Blackberry OS10 simple questions

[ Edited ]

Yop, function does not exists.

 

Maybe you can try read

How to create UI with C++\

https://developer.blackberry.com/native/documentation/cascades/getting_started/first_app/lightning_c...

or QML

https://developer.blackberry.com/native/documentation/cascades/getting_started/first_app/lightning_c...

 

Or you can use findChild function

Example:

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

// Create root object for the UI
AbstractPane *root = qml->createRootObject<AbstractPane>();

Container *container = root->findChild<Container*>("container");
if (!container){
    qDebug() << "Error find container";
}else{
    Label label;
    label.setText("Works");
    container->add(&label);
} // Set created root object as the application scene app->setScene(root);

 QML main.qml

import bb.cascades 1.2

Page {
    Container {
        objectName: "container"
        
    }
}

 

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog