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
Posts: 24
Registered: ‎05-16-2013
My Device: Developer
My Carrier: Developer
Accepted Solution

Custom Control not Working ?

I have tried to implement custom control for my app,but it is not working from the initial phase itself...  Smiley Sad Smiley Sad

 

Please help...

 

/*
 * ImageSlider.cpp
 *
 *  Created on: Jun 10, 2013
 *      Author: lalthomas
 */

#include "ImageSlider.h"
#include <bb/cascades/CustomControl>
#include <bb/cascades/Container>
#include <bb/cascades/DockLayout>
#include <bb/cascades/ImageView>
#include <bb/cascades/TouchEvent>
#include <bb/cascades/AbsoluteLayout>

using namespace bb::cascades;

ImageSlider::ImageSlider (Container *parent)
: CustomControl(parent)
{
	m_Container = new Container();
	m_Container->setLayout(new AbsoluteLayout());

	Sample->setText("Hello");
	m_Container->add(Sample);

	for(int i=0;i<12;i++){
		m_Trackers[i] = ImageView::create().image(QUrl("asset:///images/bullet-24-24.png"));
		m_Container->add(m_Trackers[i]);
	}
	setRoot(m_Container);
	setPreferredSize(600,600);
}

 

 

/*
 * ImageSlider.h
 *
 *  Created on: Jun 10, 2013
 *      Author: lalthomas
 */

#ifndef IMAGESLIDER_H_
#define IMAGESLIDER_H_

#include <bb/cascades/CustomControl>
#include <bb/cascades/Image>
#include <bb/cascades/ImageView>
#include <bb/cascades/Label>

namespace bb {
namespace cascades {
class Container;
class ImageView;
class TouchEvent;
}
}

class ImageSlider: public bb::cascades::CustomControl {
	Q_OBJECT
public:
	ImageSlider(bb::cascades::Container *parent = 0);
	virtual ~ImageSlider();
private:
    float m_width;
    float m_height;
    bb::cascades::ImageView *m_Trackers[12];
    bb::cascades::ImageView *m_SlideImages[12];
    bb::cascades::Image m_Tracker;
    bb::cascades::Image m_TrackerCurrent;
    bb::cascades::Container *m_Container;
    bb::cascades::Label *Sample;
};

#endif /* IMAGESLIDER_H_ */

 

// Default empty project template
import bb.cascades 1.0

// creates one page with a label
Page {
    Container {
        layout: DockLayout {}        
        Label {
            text: qsTr("Hello World")
            textStyle.base: SystemDefaults.TextStyles.BigText
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
        ImageSlider {
            id: slider
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
        }
    }
}

 

 

// Default empty project template
#include "applicationui.hpp"
#include "ImageSlider.h"

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

using namespace bb::cascades;

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

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

	// Register our custom control
	qmlRegisterType<ImageSlider>("custom.lib", 1, 0, "ImageSlider");
    // 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);

    // If the QML document is valid, we process it.
       if (!qml->hasErrors()) {

           // Create the application Page from QMLDocument.
           Page *appPage = qml->createRootObject<Page>();

           if (appPage) {
               // Set the main scene for the application to the Page.
               Application::instance()->setScene(appPage);
           }
       }
}

 

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Custom Control not Working ?

At a glance, I would say.. add this in your QML file...

 

import custom.lib 1.0

 

Developer
Posts: 24
Registered: ‎05-16-2013
My Device: Developer
My Carrier: Developer

Re: Custom Control not Working ?

Even after including the line app craches when it is launched.... Smiley Sad

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Custom Control not Working ?

Hey there..

 

In your ImageSlider constructor, I think you're missing this line...

 

    Sample = new Label();

 

Retired
Posts: 252
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: Custom Control not Working ?

Hi, i have confirmed that adding the two codelines suggested by jalue solve your issue.

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker