Hi all,
I'm running into a strange problem:
- I have a QObject which holds a list of items
class CGrowersList
: public QObject{
Q_OBJECT
...
QQmlListProperty<CGrower> growers();
Q_INVOKABLE CGrower* byShortName(const QString& shortName) const;
private:
QList<CGrower*> m_growers;
class CGrowersList : public QObject
{
Q_OBJECT
...
QQmlListProperty<CGrower> growers();
Q_INVOKABLE CGrower* byShortName(const QString& shortName) const;
private:
QList<CGrower*> m_growers;
To copy to clipboard, switch view to plain text mode
- The CGrowerList item is published to qml via contextproperty in my main.cpp:
CGrowersList growers;
viewer.rootContext()->setContextProperty("growers", &growers);
CGrowersList growers;
viewer.rootContext()->setContextProperty("growers", &growers);
To copy to clipboard, switch view to plain text mode
- the m_growers are used as a model for list:
QQmlListProperty<CGrower> CGrowersList::growers(){
return QQmlListProperty<CGrower>(this, m_growers);
}
QQmlListProperty<CGrower> CGrowersList::growers(){
return QQmlListProperty<CGrower>(this, m_growers);
}
To copy to clipboard, switch view to plain text mode
this works so far so good.
Problem appears when i try to invoke the methode "byShortName" from within the qml-code.
CGrower* CGrowersList::byShortName(const QString& shortName) const {
qDebug() << "enter by shortname: " << shortName;
foreach (CGrower* item, m_growers) {
if (item->shortName().compare(shortName) == 0){
qDebug() << "return : " << item->name();
return item;
}
}
qDebug() << "return nullgrower: ";
return m_nullGrower;
}
CGrower* CGrowersList::byShortName(const QString& shortName) const {
qDebug() << "enter by shortname: " << shortName;
foreach (CGrower* item, m_growers) {
if (item->shortName().compare(shortName) == 0){
qDebug() << "return : " << item->name();
return item;
}
}
qDebug() << "return nullgrower: ";
return m_nullGrower;
}
To copy to clipboard, switch view to plain text mode
It works 2-10 times and suddenly I get a Fatal signal 11 (SIGSEGV). The methode is entered
correctly but when the methode tries to access its member (m_growers) it crashes.
I call several methodes on the CGrowersList wrapper, e.g. sort, filter,... Everything works perfectly
as long as I don't return a object. Same problem appears if I try to use a "at" function.
Any ideas?
Thx,
Patrik
Bookmarks