Hi,
I have these two situations:
class myClass
{
...
}
class myModel : public QAbstractTableMOdel
{
public:
...
Q_INVOKABLE myClass getElement(int index)
{
if(0 > index || index >= m_Data.size())
return 0;
return m_Data[index];
}
private:
QList<myClass> m_Data;
}
class myClass
{
...
}
class myModel : public QAbstractTableMOdel
{
public:
...
Q_INVOKABLE myClass getElement(int index)
{
if(0 > index || index >= m_Data.size())
return 0;
return m_Data[index];
}
private:
QList<myClass> m_Data;
}
To copy to clipboard, switch view to plain text mode
calling the getElement(index) function from qml works just fine. However, if I change to pointers like so:
{
Q_OBJECT
...
}
class myModel : public QAbstractTableMOdel
{
public:
...
Q_INVOKABLE myClass* getElement(int index)
{
if(0 > index || index >= m_Data.size())
return 0;
return m_Data[index];
}
private:
QList<myClass*> m_Data;
}
class myClass : public QObject
{
Q_OBJECT
...
}
class myModel : public QAbstractTableMOdel
{
public:
...
Q_INVOKABLE myClass* getElement(int index)
{
if(0 > index || index >= m_Data.size())
return 0;
return m_Data[index];
}
private:
QList<myClass*> m_Data;
}
To copy to clipboard, switch view to plain text mode
Then it first works fine as well. But every now and then I get a segfault when calling the getElement(index) function from qml. I don't understand how it can work most of the time but suddenly create a segfault. Also, I have no clue how to debug it any further. I narrowed it down to the actual function call but I have no clue why it would give a segfault. Can anyone tell my why this might be happening?
Bookmarks