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: 193
Registered: ‎12-29-2010
My Device: Bold 9900
My Carrier: Rogers
Accepted Solution

No List showing up

I've tried replicating the stampCollector app to create a list that I can put in my app. Whenever I run it though, I get a blank screen. I can't seem to figure out why though...Any help would be appreciated... 

 

here is my code:

 

main.qml

import bb.cascades 1.0

TabbedPane {
    id: mainTabPage
    showTabsOnActionBar: true
    
    // Country Tab
    Tab {
        title: "Countries"
        NavigationPane {
            id: countryTabNav
            property variant _countryView;
            Page {
                Container {
                    ListView {
                        id: countryList
                        objectName: "countryList"
                        listItemComponents: [
                            ListItemComponent {
                                type: "listItem"
                                StandardListItem {
                                    title: ListItemData.country
                                    status: ListItemData.population
                                    description: ListItemData.capital
                                }
                            }
                        ]
                        
                        onTriggered: {
                            var chosenItem = dataModel.data(indexPath);
                            _countryView = chosenItem;
                            countryTabNav.deprecatedPushQmlByString("countryDetail.qml");
                        }
                    }
                    
                    //-- define tab content here
                    layout: StackLayout {
                    }
                    
                }
            }
        }
    }
}

 

 

app.cpp

#include "app.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Container>
#include <bb/cascades/GroupDataModel>
#include <bb/cascades/ListView>
#include <bb/cascades/NavigationPane>
#include <bb/cascades/QmlDocument>
#include <bb/data/JsonDataAccess>

using namespace bb::cascades;
using namespace bb::data;

App::App() {
	QmlDocument *qml = QmlDocument::create("main.qml");
	//-- setContextProperty expose C++ object in QML as an variable
	//-- uncomment next line to introduce 'this' object to QML name space as an 'app' variable
	//qml->setContextProperty("app", this);

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

	// ListView Model
	ListView *countryList = root->findChild<ListView*>("countryList");
	setupCountryListModel(countryList);

	Application::setScene(root);
}

void App::setupCountryListModel(ListView *countryList) {
	JsonDataAccess jda;
	QVariantList mainList = jda.load("app/native/assets/countries.json").value<QVariantList>();

	if (jda.hasError()) {
		bb::data::DataAccessError error = jda.error();
		qDebug() << "JSON loading error: " << error.errorType() << ": "
				<< error.errorMessage();
		return;
	}

	GroupDataModel *countryModel = new GroupDataModel(QStringList() << "country");
	countryModel->setParent(this);
	countryModel->insertList(mainList);
	countryModel->setGrouping(ItemGrouping::ByFullValue);

	countryList->setDataModel(countryModel);

}

 

 

 

app.hpp

#ifndef APP_H
#define APP_H

#include <QObject>
#include <bb/cascades/Application>

using namespace bb::cascades;

namespace bb
{
    namespace cascades
    {
        class ListView;
    }
}

/*!
 * @brief Application GUI object
 */
class App : public QObject
{
    Q_OBJECT
public:
    App();

private:
    void setupCountryListModel(ListView *countryList);
};

#endif // ifndef APP_H

 

 

countries.json

[
	{ 
		"country": "Canada"
		"capital": "Ottawa"
		"population": "23"
	},
	
	{ 
		"country": "India"
		"capital": "New Delhi"
		"population": "300"
	},
	
	{ 
		"country": "USA"
		"capital": "Washington D.C."
		"population": "100"
	}
]

 

Thanks

 

Developer
Posts: 193
Registered: ‎12-29-2010
My Device: Bold 9900
My Carrier: Rogers

Re: No List showing up

Nvm, my JSON file wasn't properly formatted. 

 

Problems with working late at night.