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
burakk
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold
My Carrier: Turkcell

Accessing an Object (in attachedObjects) in Another QML

Hi,

 

I have two QML files, one main.qml that is the main page with a NavigationPane:

 

NavigationPane {
    id: nav
    
    property variant player: myPlayer
    
    onCreationCompleted: {
        Qt.nav = nav;
        Qt.catList = categoriesList;
        Qt.favoritespagedef = favoritespagedef;
        //Qt.myPlayer = myPlayer;
        
        myPlayer.play();
    }

    onPopTransitionEnded: {
        page.destroy();
    }

    attachedObjects: [
        MediaPlayer {
            id: myPlayer  
            sourceUrl: "http://some.url.com/stream" 
            onSourceUrlChanged: {
            	myPlayer.prepare();
            	myPlayer.play();
            }
            

        GlobalSettings {
            id: settings
        }
    ]

    Page {
        id: categoryListPage
       
        Container {
           
        .
        .
        .

        } // end of top-level Container

    } // end of Page

}// end of Navigation Page

 

 

and a PlayingPage.qml:

 

import bb.cascades 1.0
import Network.RequestStreamUrl 1.0
import Network.RequestTrackInfo 1.0
import Network.RemoteImageView 1.0

Page {
    
    property alias chname: channelName.text
    property int cid
    
    titleBar: CustomTitleBar {
        objectName: "tb"
        customTitle: "BB 10 App"
        
        onFavImageButtonClicked: {      
            var favoritesPage = Qt.favoritespagedef.createObject();
            Qt.nav.push(favoritesPage);
        }
    }
    
    Container {
        
        Label {
            id: channelName
            text: "not yet specified"
        }
        
        Label {
            objectName: "streamUrl"
            id: streamUrl
            
            onTextChanged: {
                var url = streamUrl.text;
            }
        }
        
        Label {
            id: lblArtistName
            text: "artist name"
        }
        
        Label {
            id: lblSongTitle
            text: "song title"
        }
        
        Label {
            id: lblAlbumTitle
            text: "album title"
        }
        
        Label {
            id: lblImageUrl
            text: "image url"
        }       

        RemoteImageView {
             id: remoteImageView
	}
    }

    attachedObjects: [
        RequestStreamUrl {
            id: netstream
            onComplete: {
               streamUrl.text = respStreamUrl;
               Qt.nav.player.stop();
               Qt.nav.player.reset();
               Qt.nav.player.sourceUrl = respStreamUrl;            
            }
        }    
    ]
}

 

I'd like to access the MediaPlayer object myPlayer in the main.qml from PlayingPage.qml without adding it into the Qt object. As you can see in the code below, I added a property:

 

property variant player: myPlayer

but still have to access it by:

 

 Qt.nav.player.stop();
 Qt.nav.player.reset();
 Qt.nav.player.sourceUrl = respStreamUrl;  
I am looking for a way to access the MediaPlayer object wihout using the Qt object and C++ code. Thanks in advance
Please use plain text.
Developer
bmorr
Posts: 232
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: Accessing an Object (in attachedObjects) in Another QML

interested in finding out how to do this as well.  Normally I'd attach the object again in the second QML, is this not possible in the second QML?

Please use plain text.
Developer
bmorr
Posts: 232
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: Accessing an Object (in attachedObjects) in Another QML

[ Edited ]

This is what I did to access an attached dataModel another QML in my own app:

 

first qml:

 

NavigationPane{

ListView{

onTriggered: { // When an item is selected we push the recipe Page in the chosenItem file attribute. var chosenItem = dataModel.data(indexPath); // Create the content page and push it on top to drill down to it. var contentpage = contentPageDefinition.createObject(); // Set the content properties to reflect the selected image. contentpage.contentName = chosenItem.name contentpage.contentDescription = chosenItem.description contentpage.contentDate = chosenItem.datefield contentpage.contentLat = chosenItem.lat contentpage.contentLon = chosenItem.lon contentpage.contentCategory = chosenItem.categoryfield contentpage.contentURL = chosenItem.mapurl contentpage.contentCustomerID = chosenItem.customerID contentpage.contentItemPic = chosenItem.itempic // Push the content page to the navigation stack navigationPane.push(contentpage); } } } attachedObjects: [ ComponentDefinition { id: contentPageDefinition source: "Listitem.qml" } ] //! [0] } onPopTransitionEnded: { // Transition is done destroy the Page to free up memory. page.destroy(); } }

 

 second qml:

 

Page {
id: listItemPage

    property alias contentName: listItemName.text
    property alias contentDescription: listItemDescription.text
    property alias contentDate: listItemDatefield.text
    property alias contentCategory: listItemCategoryfield.text
    property alias contentLat: listItemLat.text
    property alias contentLon: listItemLon.text
    property alias contentURL: listItemURL.text
    property alias contentCustomerID: listItemID.text
    property alias contentItemPic: listItemPic.text
    
    titleBar: TitleBar {
        id: itemTitle
        title: qsTr("Place Details") + Retranslate.onLanguageChanged
    }
    
ScrollView {
	scrollViewProperties.scrollMode: ScrollMode.Vertical

    Container {
        
        layout: StackLayout {
        }
        //! [0]
            Container {

                id: root
                layout: DockLayout {
                }
            MapView {
                ....
                latitude: listItemLat.text
                longitude: listItemLon.text
.....
            }

            }
        }
        Container {            
            topPadding: 10
            leftPadding: 30
            rightPadding: 30
            bottomPadding: 30
            Container {
                topPadding: 10
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }
                Label {
                    text: qsTr("Category") + ": " + Retranslate.onLanguageChanged
                    textStyle.fontSize: FontSize.Medium
                    textStyle.textAlign: TextAlign.Left
                    textStyle.color: Color.DarkMagenta
                    textStyle.fontWeight: FontWeight.Bold
                }
                Label {
                    id: listItemCategoryfield
                    text: ListItemData.categoryfield
                    textStyle.textAlign: TextAlign.Left
                    
                  }
            }
            Divider {
                
            }
            Container {
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }
                
                Label {
                    id: listItemName
                    text: ListItemData.name
                    textStyle.fontSize: FontSize.Large
                    textStyle.textAlign: TextAlign.Left
                    multiline: true
                    minWidth: 500
                    verticalAlignment: VerticalAlignment.Center
                
                }
                Label {
                    id: listItemDatefield
                    text: ListItemData.datefield
                    textStyle.textAlign: TextAlign.Center
                    horizontalAlignment: HorizontalAlignment.Center
                    verticalAlignment: VerticalAlignment.Center
                    minWidth: 200
                }
            }
            Divider {
                
            }
            Container {
                layout: StackLayout {
                    orientation: LayoutOrientation.TopToBottom
                }
            Label {
                text: qsTr("Description") + ":" + Retranslate.onLanguageChanged
                textStyle.fontSize: FontSize.Medium
                textStyle.textAlign: TextAlign.Left
                bottomPadding: 20
                textStyle.color: Color.DarkMagenta
                textStyle.fontWeight: FontWeight.Bold
            }
            Label {
                id: listItemDescription
                text: ListItemData.description
                textStyle.textAlign: TextAlign.Left
                textStyle.fontSize: FontSize.Small
                multiline: true
            }
        }
        }
    }
}
    attachedObjects: [
        Label {
          id: listItemID
          text: ListItemData.customerID
        },
        Label {
            id: listItemLat
            text: ListItemData.lat
        },
        Label {
           id: listItemLon 
           text: ListItemData.lon
        },
        Label {
          id: listItemURL
          text: ListItemData.mapurl  
        },
        LocationMapInvoker {
            id: locationInvoker
        
        
        },
        RouteMapInvoker {
            
            id: routeInvoker
        
        },
Label: {
id: itemPic
text: listItemData.itempic
} ] }

 

Please use plain text.
Developer
ekke
Posts: 1,413
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Accessing an Object (in attachedObjects) in Another QML

for this kind of stuff I'm using functions in NavigationPane like

 

function stopPlayer(url){

 myPlayer.stop()

 myPlayer.reset()

 myPlayer.sourceUrl = url

}

 

and then from all pages pushed on top of the navigation pane simply do

 

nav.stopPlayer(myUrl)

 

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

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
burakk
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold
My Carrier: Turkcell

Re: Accessing an Object (in attachedObjects) in Another QML

[ Edited ]

I guess it should be:

 

Qt.nav.stopPlayer(myUrl);

 

instead of

 

nav.stopPlayer(myUrl);

 

?

Please use plain text.
Developer
ekke
Posts: 1,413
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Accessing an Object (in attachedObjects) in Another QML


burakk wrote:

I guess it should be:

 

Qt.nav.stopPlayer(myUrl);

 

instead of

 

nav.stopPlayer(myUrl);

 

?


NO ;-)

 

If your Page is pushed on top of the NavigationPane,

then the id of the root is known

 

I'm using this always

My app has a TabbedPane as rootPane

and all NavigagtionPane from single Tabs are named navPane

 

then from all Pages pushed on a NavigationPane I can access functions and properties from navPane

and also from rootPane

 

think about the tree of QML Pages - all from root to current page is 'known'

only Sheets are breaking this - you can push Pages also on Sheets, but then only have access back to the Sheet, not the underlying NavigationPane or TabbedPane

 

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

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
burakk
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold
My Carrier: Turkcell

Re: Accessing an Object (in attachedObjects) in Another QML

[ Edited ]

Consider this:

 

Page {
    
    titleBar: CustomTitleBar {
        objectName: "tb"
        customTitle: "Bla bla bla"
        
        onFavImageButtonClicked: {      
            var favoritesPage = Qt.favoritespagedef.createObject();
            Qt.nav.push(favoritesPage);
        }
    }

.
.
.

}

 

This is the page: PlayingPage.qml, pushed on top the NavigationPane nav in main.qml.

 

nav.push(favoritesPage) does not work, but Qt.nav.push(favoritesPage) does.

 

According to your explanation (which is correct, I believe), nav.push must work since the root NavigationPane is known, but it doesn't. I am a bit confused here...

 

 

Please use plain text.
Developer
ekke
Posts: 1,413
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Accessing an Object (in attachedObjects) in Another QML

access to properties and functions are working this way

I'm never using the Qt. Object

prefer to use a function like

 

pushFavoritesPage(){

  ....

}

 

then all my stuff to push pages on top are at one place: at the NavigationPane

from  where I also watch for all events like onPopTransitionEnded() to destroy() the component

 

but as always: there are many ways HowTo solve this ;-)

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

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Developer
burakk
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold
My Carrier: Turkcell

Re: Accessing an Object (in attachedObjects) in Another QML

adding the pushFavoritesPage() function eliminated one more item from the Qt object, thanks :smileyhappy:

 

But still, I have to use Qt.nav.pushFavoritesPage() when in another QML, nav.pushFavoritesPage() simply does not work me.

 

Anyway, thanks for the explanations. 

Please use plain text.
Developer
ekke
Posts: 1,413
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Accessing an Object (in attachedObjects) in Another QML


burakk wrote:

adding the pushFavoritesPage() function eliminated one more item from the Qt object, thanks :smileyhappy:

 

But still, I have to use Qt.nav.pushFavoritesPage() when in another QML, nav.pushFavoritesPage() simply does not work me.

 

Anyway, thanks for the explanations. 


curious - should work

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

BlackBerry Elite Developer
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.