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: 367
Registered: ‎11-25-2009
My Device: Not Specified

Referencing ActivityIndicators from different QML files

Hello, I have a NavigationPane (main.qml) with three ComponentDefinitions, used to point to three different QML files:

 

secondpage.qml

thirdpage.qml

loginsheet.qml

 

Both main.qml and loginSheet.qml contain an ActivityIndicator.  What is the recommended way to reference two different QML documents (and two different ActivityIndicators) in my C++ code?

 

I don't currently have my code in front of me, so the code below is mostly from memory.  Please excuse any small errors.

 

I currently reference the ActivityIndicator on main.qml with:

 

CascadesApp::CascadesApp(bb::cascades::Application *app)
{
    QmlDocument *qml = ::create("asset:///main.qml").parent(this);
    qml->setContextProperty("app", this);

    AbstractPane *root = qml->createRootObject<AbstractPane>();

ActivityIndicator *myindicator = qml->findChild<ActivityIndicator*>("myIndicator"); app->setScene(root); }

 

I have tried adding the following, with no success:

QmlDocument *qmlLogin = ::create("asset:///loginSheet.qml").parent(this);
qmlLogin ->setContextProperty("app", this);
ActivityIndicator *myindicator = qmlLogin ->findChild<ActivityIndicator*>("myIndicator");

 

main.qml:

NavigationPane {
	onCreationCompleted: {
		if(!app.isAuthenticated())
			var loginSheet = loginSheetDefinition.createObject();
			loginSheet.open();
		}
    }
    id: navigationPane
    Page {
        Container {
            Label { 
                text: "Main page"
            }
			Button {
				id: button1
				text: "Open Page 2"
				onClicked: {
					var page1 = secondPageDefinition.createObject();
                    navigationPane.push(page1);
				}
			}
			Button {
				id: button1
				text: "Open Page 3"
				onClicked: {
					var page2 = thirdPageDefinition.createObject();
                    navigationPane.push(page2);
				}
			}
            ActivityIndicator {
                id: myIndicator
                preferredWidth: 100
            }
            attachedObjects: [
                ComponentDefinition {
                    id: secondPageDefinition;
                    source: "secondpage.qml"
                },
                ComponentDefinition {
                    id: thirdPageDefinition;
                    source: "thirdpage.qml"
                },
                ComponentDefinition {
                    id: loginSheetDefinition;
                    source: "loginSheet.qml"
                }
            ]
        }
    }
}

 

This brings up another question that I have.  With multiple QML files, should I have multiple C++ files for each?  Or does one typically use one C++ file for multiple QML documents?  I guess that I'm just confused on how to structure such a project.

 

Thanks.

 

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Referencing ActivityIndicators from different QML files

give it a different objectName
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Referencing ActivityIndicators from different QML files

With a different objectName, would my attempted solution be the recommended way to reference the second ActivityIndicator?