[Interest] Is this a BUG in Qt, Please let me know if I need to report this as a bug in QT5 Beta.

Satya Praveen Ganapathi praveen.s at hmie.co.in
Mon Nov 5 12:21:46 CET 2012


Hi,

 

I have already posted a similar issue on Qt but I haven't received any
reply.

 

Below code works fine with "ListView" view in  qml, but if it replace
the view with Pathview then the program exits with code 0 error .

 

If I'm updating a PathView with dynamic list Model then the program
(view ) terminates. 

 

Is this a BUG in Qt, Please let me know if I need to report this as a
bug in Qt 5.0 Beta.

 

 

 

MODEL.CPP

 

#include "model.h"

#include <QDebug>

 

RouteItem::RouteItem(QString value, const QString &lable, Object
*parent):QObject(parent),mRouteVal(value),mLabel(lable)

{

}

RouteItem::`RouteItem(){}

QString RouteItem::label()const{

Return mLable;

}

QString routeItem::routeVal() const

{return nRouteVal;

}

RouteControlModel::RouteControlModel(QObject *parent):QAbstractItemModel
(parent) {

QHash<int,QByteArray> roles;

Roles[LableRole] = "lable";

Roles[RouteValRole] = "routeVal";

setRoleNames(roles);

QList<QString> list = supportedRouteValues();

Int I = list.count();

QString lable;

While(i>0){

i--;

addRouteItem(list[i],label);

}

QList<QString> RouteControlModel::supportedRouteValues() const

{

QList<QString> dummy;

dummy.append("restaurant");

dummy.append("bar");

dummy.append("hotel");

return dummy;

}

RouteControlModel::~RouteControlModel(){

}

Void RouteControlModel::addRouteItem(QString value, QString label)

{

beginInsertRows(QModelIndex(), rowCount(), rowCount());

RouteItem* item = new RouteItem(value, lable, this);

mRouteList.append(item);

endInsertRoes();

}

Int RouteControlModel::rowCount(const QModelIndex &parent) cont

{

W_UNUSED(child);

return mRouteList.count();

}

QModelIndex RouteControlModel::parent(const QModelindex &child)

{

Q_UNUSED9chile);

Return QModelIndex();

QModelIndex RouteControlModel::index(int row, int column, const
QModelIndex &parent) const

{

Q_UNUSED(parent)

If(row <0 || row>=rowCount()||column<0||column >=columnCount()){return
QModelIndex()}

Return QAbstractItemModel::ceateIndex(row,column);

}

 

Int RouteControlModel::columnCount(const QModelIndex &parent) cont

{

Q_UNUSED(parent);

Return 1;

}

QObject* RouteControlModel::get(int listItemIndex)

{

qDebug()<<"RouteControlModel::get";

if(listITemIndex >= ) && listItemIndex < mRouteList.count())

{

qDebug()<<"RouteControlModel::get index";

return mRouteList.at(listItemIndex);

}

Else {

qDebud() <<"RouteControlModel::get() called with out-0f-bonds";

return NULL;

}

}

QVariant RouteControlModel::data(const QModelIndex & index, int role)
const

{

If(index.row() < 0 || index.row() >= mRouteList.count()){

Return QVarient();

}

If(role== LableRole){ return mRouteList[index.row()]->label();}

Else if (role == RouteValRole{ return
mRouteList[index.row()]->routeVal();}

Else { return QVarient();

}

}

 

 

-------------------------------MAIN--------------------------------

#include "model.h"

#include<QGuiApplication>

#include<qqmlcontext.h>

#include<QtQuick/qquickview.h>

Int main(int argc, char **argv)

{

QGuiApplication app(argc, argv);

RouteControlModel routeControlModel(0);

QQuickView view;

View.setResizeMode(QQuickView::SizeRootObjectToView);

QQmlcontext *ctxt = view.rootContext();

ctxt->SetContextProperty ("routeControlModel", &routeControlModel);

view.serSource(QUrl("qrc:view.qml"));

view.show();

return app.exec();

}

 

-----------------------------MODEL.h---------------

 

 

#include <QAbstractItemModl>

#include <QString>

#include<QObject>

Class RouteItem: public QObject

{ 

Q_OBJECT

Q_Property(QString label READ label NOTIFY labelChanged)

Q_PROPERTY(QString routeVal READ routeVal NOTIFY routeValChanged)

Public:

RouteItem(QString value, const QStrin &label, QObject *parent =0);

~RouteItem();

QString label() cosnt;

QString routeVal() const;

Signals:

Void routeValChanged();

Void labelChanged();

Private:

QString mRouteVal;

QString mLabel;

};

Class RouteControlModel: public QAbstractItemModel

{

Q_OBJECT

Enum RoutecontrolRoles{ LabelRole = Qt::UserRole+1, RouteValRole };

 

Public:

explicit routeControlModel(QObject *patent =0);

virtual ~RouteControlModel();

void addRouteItem(QString value, QString label);

int rowCount(const QModel Index &parent = QModelindex()) const;

int columnCount(const QModelIndex & index, int role = Qt::Displayrole);

QModelIndex parent(const QModelIndex &chile) const;

QModelIndex index(int row, int column, const QModelIndex &parent =
QModelIndex()) const;

Qlist<QString> supportedRouteValues() const;

 

Public slots:

QObject* get(int listItemIndex);

Private:

QList<RouteItem*> mrouteList;

};

 

______________________________view.qml__________________________

 

 

Import QtQuick 2.0

 

ListView{

Id:listView

Widthe:640

Height:480

Model:routeControlModel

Delegate: Text{text:routeControlModel.get9index).routeVal}

}

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121105/80f5ae09/attachment.html>


More information about the Interest mailing list