11-19-2012 01:22 PM
hi
I've tried to go through all the examples I can see, I don't think I am far aware but not getting the correct data displayed.
I create a ListView in QML, define the datasource as an attachedObject. I add data to the GroupDataModel in QML and the data is displayed. But if I try and add from c++, I see nothing. Anyone know what I'm doing wrong?
The QML:
import myLibrary 1.0
TabbedPane {
id: tabpane
showTabsOnActionBar: true
Tab
{
title: qsTr("Tab One")
Page
{
content: Container
{
attachedObjects:
[
GroupDataModel
{
id: groupDataModel
objectName: "groupDataModel"
}
]
ListView
{
id: myListView
dataModel: groupDataModel
onCreationCompleted:
{
groupDataModel.insert( {"Charlie" : "Charles"} );
groupDataModel.insert( {"Dickie" : "Bob"} );
groupDataModel.insert( {"Karen" : "Kath"} );
groupDataModel.insert( {"Sammy" : "Sims"} );
}
function itemType(data, indexPath)
{
if (indexPath.length == 1)
{
return "header";
}
return "listItem";
}
}
}
}
}
}And the main app C++ (where I am trying to add data to the datasource:
#include "Listitem.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include "WebImageView.h"
#include "Employee.hpp"
using namespace bb::cascades;
Listitem::Listitem(bb::cascades::Application *app)
: QObject(app)
{
// register my Employee class
qmlRegisterType<Employee>("myLibrary", 1, 0, "Employee");
// standard create code
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th is);
// get the top level tabbed pane and find the GroupDataModel within it
mTabbedPane = qml->createRootObject<TabbedPane>();
GroupDataModel *pModel = mTabbedPane->findChild<GroupDataModel*>("groupData Model");
// insert a new Employee object
pModel->insert(new Employee("Peter", "Piper"));
// again, standard stuff
AbstractPane *root = qml->createRootObject<AbstractPane>();
app->setScene(root);
} If I check the length of the GroupDataModel, it has increased from 4 to 5. But I think my problem is the Employee class...just not sure what! ![]()
Employee.hpp:
#include <QObject>
//using namespace bb::cascades;
class Employee : public QObject {
Q_OBJECT
Q_PROPERTY(QString firstName READ firstName WRITE setFirstName FINAL)
Q_PROPERTY(QString lastName READ lastName WRITE setLastName FINAL)
public:
Employee(QObject *parent = 0);
Employee(QString argLastName, QString argFirstName);
QString firstName();
QString lastName();
Q_SLOT void setFirstName(QString newName);
Q_SLOT void setLastName(QString newName);
QString mFirstName;
QString mLastName;
};and Employee.cpp:
#include "Employee.hpp"
Employee::Employee(QObject *parent) {}
Employee::Employee(QString argLastName, QString argFirstName)
{
mFirstName = argFirstName;
mLastName = argLastName;
}
QString Employee::firstName()
{
return mFirstName;
}
QString Employee::lastName()
{
return mLastName;
}
void Employee::setFirstName(QString newName)
{
mFirstName = newName;
}
void Employee::setLastName(QString newName)
{
mLastName = newName;
} I know its going to be something stupid, I apologise. But I just can;t see it ![]()
many thanks
11-19-2012 02:20 PM
11-19-2012 02:40 PM
hi KyleFowler
i thought by creating the listview (myListView in the above QML) that was enough? doesn't the ListView handle displaying each item in the list automatically?
thanks
11-19-2012 03:19 PM
I added section for
listItemComponents: [
ListItemComponent
{
type: "listItem"
etc
But it still only displays 4 items in the list. In my latest code I add 20 items to the groupdatamodel in the c++ code, none of them show up ![]()
11-19-2012 05:09 PM
11-19-2012 06:10 PM
hi KyleFowler
yeah, its the opposite! The ones in QML are displayed, the c++ is not.
The listitemcomponent code is:
listItemComponents: [
// The second ListItemComponent defines how "listItem" items
// should appear. These items use a Container that includes a
// CheckBox and a Label.
ListItemComponent
{
type: "listItem"
Container
{
Label
{
text: "help!!!"
textStyle
{
base: SystemDefaults.TextStyles.TitleText
fontWeight: FontWeight.Normal
}
}
} // end of Container
} // end of second ListItemComponent
] // end of listItemComponents listSo you can see, I'm not displaying the data yet, if I try listitemdata.firstname I get "undefined".
I really appreciate the support, I'd dead in the water right now.
If you could spare a few minutes, I uploaded the whole project to:
https://www.dropbox.com/s/eckejm7ihnzajs0/listitem
many thanks
11-19-2012 07:37 PM
11-20-2012 04:42 AM
I'm not able to get a pointer to the ListView so I can't then get the datasource from it.
In my C++ I have:
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th is);
// Expose this class to QML so that we can call its functions from there
qml->setContextProperty("app", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
GroupDataModel *pModel = root->findChild<GroupDataModel*>("groupDataModel") ;
Page *pPage2 = root->findChild<Page*>("zonepage");
Container *pCont = root->findChild<Container*>("myContainer");
ListView *pList = root->findChild<ListView*>("myListView");GroupDataModel returns with a valid pointer but pPage2, pCont and pList are all null, I cannot get a pointer back.
Also strange, if I change the page from being a tabbedPane to just a Page (no tabs) the c++ code successfully adds the rows to the listview.
Is this a bug?
thanks
11-20-2012 05:13 AM
I think this thread has got a bit too messy, sorry. I'll try and isolate each issue and create a clear, concise question for each ![]()
11-20-2012 11:42 AM