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
Highlighted
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later
Accepted Solution

navigation pane + network reply

void ApplicationUI::help() {
	qDebug() << "help";
	try
	{
		qDebug() << "here";
		QmlDocument *qml = QmlDocument::create("asset:///Help.qml").parent(this);

		// Create root object for the UI

		// AbstractPane *root = qml->createRootObject<AbstractPane>();
		Page *new_Page = qml->createRootObject<Page>();
		//  AbstractPane *oldScene = Application::instance()->scene();
		//  myNavi = oldScene->findChild<NavigationPane*>("guestMenuNavigation");
		myNavi2 = dynamic_cast<NavigationPane*>(root);
		//  myNavi2 = root->findChild<NavigationPane*>("guestMenuNavigation");
		if (myNavi2){
			myNavi2->push(new_Page);
			Application::instance()->setScene(myNavi2);
		}else{
			qDebug() << "Unable find NavigationPane";
		}

		QNetworkAccessManager* netManager = new QNetworkAccessManager(this);
		qDebug() << "here1";
		const QUrl url("http://demo.netvariant.com/alkhaliji/mobile/data/categories.json");
		QNetworkRequest request(url);

		QNetworkReply* reply = netManager->get(request);
		bool ok = connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
		Q_ASSERT(ok);
		Q_UNUSED(ok);

	}
	catch(...)
	{

	}
}


void ApplicationUI::onReplyFinished()
{
	qDebug() << "here2";
	QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());

	QString response;
	if (reply) {
		if (reply->error() == QNetworkReply::NoError) {
			const int available = reply->bytesAvailable();
			if (available > 0) {
				const QByteArray data(reply->readAll());
				//	QVariant jsonva(QString(data)); //= Json::parse(QString(data), true);
				// JsonDataAccess json = JsonDataAccess::loadFromBuffer(QString(data));
				JsonDataAccess jda;
				QVariant jsonva = jda.loadFromBuffer(QString(data));
				//QVariantList list = jsonva.toList;
				QVariant list = jsonva;
				emit buildList(list);
				qDebug() << "here3";
			}
		}
		reply->deleteLater();
	}
}
void ApplicationUI::buildList(QVariant list) {
	qDebug() << "here4";
	bb::cascades::QVariantListDataModel *listModel =
			new QVariantListDataModel();
	ListView* custList = root->findChild<ListView*>("customList");
	if (custList != NULL) {
		QVariantMap map;
		qDebug() << "here5";
		qDebug() << "unknown state";

		QVariantMap childJsonv1a = list.toMap();
		QVariantMap childJsonva2 = childJsonv1a["DATA"].toMap();
		QVariant childJsonva = childJsonva2["categories"];
		QVariantList childList = childJsonva.toList();
		for (QList<QVariant>::iterator it = childList.begin();
				it != childList.end(); it++) {
			qDebug() << "here6";
			map = it->toMap();
			//	map["negativeBalance"] = map.value("availableBalance").toString().startsWith("-");
			listModel->append(map);
		}
		ActivityIndicator *mActivityIndicator = root->findChild<
				ActivityIndicator*>("activityIndicator");
		mActivityIndicator->stop();
		qDebug() << "here7";
		custList->setDataModel(listModel);
	}
}

  help.qml

 

import bb.cascades 1.0


Page { 
    Container {
        
        Container {
            
            preferredWidth: Infinity
            background: style.black
            TopBar {
                id: bar
                layoutProperties: StackLayoutProperties {
                    spaceQuota: -1
                }
            }
            layoutProperties: StackLayoutProperties {
                spaceQuota: -1
            }
        }
        NetworkActivity {
            id: progressIndicator
            
            horizontalAlignment: HorizontalAlignment.Fill
            verticalAlignment: VerticalAlignment.Fill
        }
        Container {
            topPadding: 20
            ListView {
                objectName: "customList"
                id: customList           
                listItemComponents: [
                    ListItemComponent {
                        Container {
                            id: itemRoot
                            background: ListItem.selected ? Color.Transparent : Color.Transparent
                            Container {
                                leftPadding: 30
                                topPadding: 10
                                rightPadding: 10
                                bottomPadding: 10
                                
                                layout: StackLayout {
                                    orientation: LayoutOrientation.LeftToRight
                                }
                                Container {
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.TopToBottom
                                    }
                                    layoutProperties: StackLayoutProperties {
                                        spaceQuota: 1
                                    }
                                    Label {
                                        text: ListItemData.label
                                        textStyle.base: SystemDefaults.TextStyles.TitleText
                                        textStyle.color: Color.create("#ff333333")
                                    }
                                }
                                Container {
                                    verticalAlignment: VerticalAlignment.Center
                                    horizontalAlignment: HorizontalAlignment.Right
                                    layout: StackLayout {
                                        orientation: LayoutOrientation.LeftToRight
                                    }
                                    ImageView {
                                        imageSource: "asset:///images/ic_right_arrow.png"
                                    }
                                }
                            }
                            Container {
                                background: Color.create("#ffE0E0E0")
                                preferredHeight: 1
                                Divider {
                                    maxHeight: 1
                                    minHeight: 1
                                
                                }
                            }
                        }
                    
                    
                    
                    }
                
                
                ]
                onTriggered: {
                    
                
                }
            }
        }
}
attachedObjects: [
    Style {
        id: style
    }
]
}
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: navigation pane + network reply

what I have here, a qml page where i display a list .
first time i enter the page network called successfully and i bring data to display ( turn off activityindicator once brought).

once i go back in my navigation pane..and reopen this page. on network reply i get activityindicator loopin forever and no list. whats reason?
Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: navigation pane + network reply

here is first first qml. On click of help , i call help function..which adds help.qml to the navigation pane.

First time it opens right, activityindicator  ..then indicator goes off and list shows up

 

i go back, reopen the help page..activity indicator loops forever..doesnt go away no list shows up.

it has to do with navigation pane then network call..cause as u see inqdebug i am getting values right

 

 

import bb.cascades 1.0
import bb.system 1.0

NavigationPane {
    id: guestMenuNavigation
    objectName: "guestMenuNavigation"
    onPopTransitionEnded: {
        page.destroy();
    }
Page {
    
    Container {
        background: style.bgColor
        TopHeader 
        {
            id: header      
        }  
        Container {
            leftPadding: 20
            rightPadding: 20
            bottomPadding: 20
            layout: StackLayout {
                orientation: LayoutOrientation.BottomToTop
            }
            layoutProperties: StackLayoutProperties {
                spaceQuota: 1
            }
            
            Container { 
                topPadding: 10 
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }   
                Button {
                    rightMargin: 10
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1
                    }
                    imageSource: "asset:///images/ic_help.png"
                    text:  qsTr("help")+Retranslate.onLocaleOrLanguageChanged
                    onClicked: {     
                        alkhaliji.help();
                    }
                } 
                Button {
                    rightMargin: 10
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1
                    }
                    imageSource: "asset:///images/ic_phone.png"
                    text: qsTr("contactUs")+Retranslate.onLocaleOrLanguageChanged
                    onClicked: {
                        alkhaliji.contactUs();
                    }
                }           
            }
            Container {
                topPadding: 10 
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }
                Button {
                    rightMargin: 10
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1
                    }
                    imageSource: "asset:///images/ic_marker.png"
                    text: qsTr("atmLocator")+Retranslate.onLocaleOrLanguageChanged
                    onClicked: {
                       
                    }
                }
                Button {
                    rightMargin: 10
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1
                    }
                    imageSource: "asset:///images/ic_display.png"
                    text: qsTr("fullWebsite")+Retranslate.onLocaleOrLanguageChanged
                    onClicked: {
                        alkhaliji.openWebsite();
                    }
                } 
            }
            Container {
                topPadding: 10 
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                } 
                Button {
                    rightMargin: 10
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1
                    }
                    imageSource: "asset:///images/ic_user.png"
                    text: qsTr("login")+Retranslate.onLocaleOrLanguageChanged
                    onClicked: {
                            var page = loginPage.createObject();
                            guestMenuNavigation.push(page);
                    }
                }
                Button {
                    
                    rightMargin: 10
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1
                    }
                    imageSource: "asset:///images/ic_id.png"
                    text: qsTr("register")+Retranslate.onLocaleOrLanguageChanged
                    onClicked: {
                        var page = register.createObject();
                        guestMenuNavigation.push(page);                    
                    }
                }
            }
        }
    }

    attachedObjects: [
        ComponentDefinition {
            id: loginPage
            source: "Login.qml"
        },
        ComponentDefinition {
            id: register
            source: "Register.qml"
        },
        Style {
                    id: style
        },
        SystemDialog {
            id: errorDialog
            objectName: "errorDialog"
            title: qsTr("Something went wrong.")
            confirmButton.label: qsTr("Launch Settings")
            
            onFinished: {
                if (value == SystemUiResult.ConfirmButtonSelection) {
                    // The app settings object can also
                    // launch the system settings app.
                    alkhaliji.permissions();
                }
            }
        }
    ]


}
}

 

Developer
Posts: 813
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: navigation pane + network reply

solution is var page = help.createObject();
guestMenuNavigation.push(page);

using this instead of using c++ to push and pop. The question i have no qnetworkmanager s working by caching... how to avoid caching?