01-15-2013 09:11 PM - edited 01-15-2013 09:13 PM
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(List ItemData.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 ![]()
Slot code for good measure:
void App::commentUrlClicked(QString url)
{
qDebug() << "url click: " << url;
}
01-15-2013 09:42 PM
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.
01-16-2013 01:17 AM
create a function in your listview
from triggered in list item call this function
the function itself should know your signal
01-16-2013 04:09 PM - edited 01-16-2013 04:10 PM
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: {