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: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Connecting a ListView signal to a C++ slot

[ Edited ]

If I have access to a qml page I have created in C++, how can I properly define a signal in the QML, and attach to that slot in C++.

 

I am emitting the signal from inside of a container within the listItemComponents of a ListView in the QML document. The signal is not being properly passed, right now :/

 

C++

commentsPageDocument = QmlDocument::create("asset:///commentsPage.qml");
	if (!commentsPageDocument->hasErrors()) {
		mCommentsPage =  commentsPageDocument->createRootObject<Page>();
	}

	ListView* v = mCommentsPage->findChild<ListView*>("commentsList");

	QObject::connect(
		v,
		SIGNAL(urlClicked(QString)),
		this,
		SLOT(commentUrlClicked(QString)));

 QML

Page {
    id: commentsListPage
    objectName: "commentsPage"
    
    Container {  
        ListView {
            signal urlClicked(string url_clicked)
            id: commentsList
            objectName: "commentsList"
            listItemComponents: [
                
                ListItemComponent {
                    type: "commentListItem"
                    Container {
                        layout: StackLayout {}
                        Label{	                        
                            text: "<html><p>" + parseAndHandleHyperlinks(cleanseCommentString(ListItemData.body)) + "</p></html>"
	                    multiline: true
	                    verticalAlignment: VerticalAlignment.Bottom
	                    horizontalAlignment: HorizontalAlignment.Left
	                    textStyle.fontSize: FontSize.XXSmall
	                    content {
	                        flags: TextContentFlag.ActiveText
                            }
	                    activeTextHandler: ActiveTextHandler {
	                        onTriggered: {	                           
	                                // Abort the default action for the active text if the active text
	                                // contains a href.
	                                if (event.href != null) {
	                                    //TODO: emit signal for handling in C++.
	                                    event.abort();
                                            //SIGNAL TO HANDLE IN C++
	                                    urlClicked(event.href);
	                                }
	                            }
	                        }
	                    }

 

Error:

[        phone_number_update_options: 376:15]: PHONE_NUMBER_LIB: cpd_capable not found and set to false.
file:///apps/com.brennan.comments.testDev_nan_comments2674aa67/native/assets//CommentsPage.qml:112: ReferenceError: Can't find variable: urlClicked

 I'm pretty sure that phone number lib stuff is unrelated and have no idea why it is there, but it only is printed when I try to emit that signal, so maybe it's related in some way Smiley Frustrated

 

Slot code for good measure:

void App::commentUrlClicked(QString url)
{
	qDebug() << "url click: " << url;
}

 

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: Connecting a ListView signal to a C++ slot

I suspect since the ListItem is emitting the signal, and the signal is declared in the ListView, there is some disconnect happening. I'm just not exactly sure if that is true, or how to fix it if it is.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Connecting a ListView signal to a C++ slot

create a function in your listview

from triggered in list item call this function

the function itself should know your signal

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Highlighted
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: Connecting a ListView signal to a C++ slot

[ Edited ]

How can I emit the list item triggered SIGNAL from within the ActiveTextHandler onTriggered SLOT of the list item? ListItem appears to be out of scope at that point.

 

activeTextHandler: ActiveTextHandler {
	                        onTriggered: {

 

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!