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
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

C++ created gesture handler not working

Hi,

 

I am adding a TapHandler to a ScrollView in C++:

ScrollView* comicScrollView = comicReader->findChild<ScrollView*>("comicScrollView");
TapHandler* singleTapHandler = TapHandler::create();
if(connect(singleTapHandler, SIGNAL(tapped(bb::cascades::TapEvent*)), this, SLOT(onTap(bb::cascades::TapEvent*))))
	{
	qDebug() << "Succesfully connected the single tap handler";
}
comicScrollView->addGestureHandler(singleTapHandler);

This is the slot:

 

void ComicReader::onTap(bb::cascades::TapEvent* tapEvent)
{
	qDebug() << "There was a tap!";
}

 

And this it the QML file:

 

import bb.cascades 1.0

Page {
    Container {
        objectName: "comicPageContainer"
        background: backgroundPaint.imagePaint
        ScrollView {
            objectName: "comicScrollView"
            scrollViewProperties {
                scrollMode: ScrollMode.Both
                pinchToZoomEnabled: true 
                maxContentScale: 5
                minContentScale: 0.5
            }
		    ImageView {        
		         objectName: "comicPageView"   
		         scalingMethod: ScalingMethod.None
		         scaleX: 1.0
		         scaleY: 1.0
		    }
        }
    }
    attachedObjects: [
        ImagePaintDefinition {
            id: backgroundPaint
            imageSource: "asset:///images/shelfbackground.png"
            repeatPattern: RepeatPattern.XY
        }
    ]
}

 However, if I add the gesture handler in QML directly (just a console.log to print the coordinates) it works, when I add the gesture handler using C++ it indicates the connection was successful, but nothing happens when I tap. Any ideas what I'm doing wrong?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: C++ created gesture handler not working

[ Edited ]

Try creating a container and then add the handler to the container.  It works for me.

 

   TapHandler *tapHandler = TapHandler::create().onTapped(this,
        SLOT(onTap(bb::cascades::TapEvent*)));

myContainer->addGestureHandler(tapHandler);
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: C++ created gesture handler not working

Adding it to the Container or ImageView makes no difference, no signal is passed to the slot.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!