Memory leak? How do you know you have a memory leak?
How does the application behave?
Memory leak? How do you know you have a memory leak?
How does the application behave?
it exits with the following error log...
*** glibc detected *** /home/gyre/temp/06_filter_widget_added/bin/qcanalyzer: realloc(): invalid old size: 0x080dbf38 ***
======= Backtrace: =========
/lib/libc.so.6[0xb734dbdd]
/lib/libc.so.6(realloc+0xfe)[0xb734fb4e]
/usr/lib/libQtCore.so.4(_Z8qReallocPvj+0x24)[0xb7597bf8]
/usr/lib/libQtCore.so.4(_ZN7QString7reallocEi+0x24c)[0xb75df3b4]
/usr/lib/libQtCore.so.4(_ZN7QString6appendE5QChar+0x78)[0xb75e099a]
/usr/lib/libQtCore.so.4[0xb759abba]
/usr/lib/libQtCore.so.4[0xb7613e14]
/usr/lib/libQtCore.so.4[0xb7610a3d]
/usr/lib/libQtCore.so.4[0xb761104c]
/usr/lib/libQtCore.so.4[0xb7611498]
/usr/lib/libQtCore.so.4(_ZNK9QResource12isCompressedEv+0x1f )[0xb7611717]
/usr/lib/libQtCore.so.4[0xb7611929]
/usr/lib/libQtCore.so.4[0xb7611a4a]
/usr/lib/libQtCore.so.4(_ZN19QAbstractFileEngine6createERK7 QString+0x5b)[0xb75ea4eb]
/usr/lib/libQtCore.so.4[0xb75fe9d9]
/usr/lib/libQtCore.so.4(_ZN9QFileInfoC1ERK7QString+0x4a)[0xb75fed9a]
/usr/lib/libQtGui.so.4(_ZN5QIconC1ERK7QString+0x2e)[0xb793ba60]
/home/gyre/temp/06_filter_widget_added/bin/qcanalyzer[0x805ba16]
/home/gyre/temp/06_filter_widget_added/bin/qcanalyzer[0x8057a63]
/home/gyre/temp/06_filter_widget_added/bin/qcanalyzer(_ZNK18QAbstractItemModel5matchERK11QMod elIndexiRK8QVarianti6QFlagsIN2Qt9MatchFlagEE+0x4f3 )[0x80535c7]
/lib/libc.so.6(__libc_start_main+0xe0)[0xb72f8050]
/home/gyre/temp/06_filter_widget_added/bin/qcanalyzer(_ZNK6QFrame8sizeHintEv+0x8d)[0x8053421]
======= Memory map: ========
08048000-080b2000 r-xp 00000000 08:03 1934881 /home/gyre/temp/06_filter_widget_added/bin/qcanalyzer
080b2000-080b3000 rw-p 0006a000 08:03 1934881 /home/gyre/temp/0f54000 rw-p 00001000 08:03 3883263 /lib/libdl-2.6.1.so
b6f54000-b703c000 r-xp 00000000 08:03 5051900 /usr/lib/libX11.so.6.2.0
b703c000-b7040000 rw-p 000e8000 08:03 5051900 /usr/lib/libX11.so.6.2.0
b7040000-b704d000 r-xp 00000000 08:03 5049986 /usr/lib/libXext.so.6.4.0
b704d000-b704e000 rw-p 0000c000 08:03 5049986 /usr/lib/libXext.so.6.4.0
b704e000-b7071000 r-xp 00000000 08:03 5051365 /usr/lib/libfontconfig.so.1.2.0
b7071000-b7079000 rw-p 00023000 08:03 5051365 /usr/lib/libfontconfig.so.1.2.0
b7079000-b707a000 rw-p b7079000 00:00 0
b707a000-b70e5000 r-xp 00000000 08:03 1032250 /usr/lib/libfreetype.so.6.3.16
b70e5000-b70e9000 rw-p 0006a000 08:03 1032250 /usr/lib/libfreetype.so.6.3.16
b70e9000-b70eb000 r-xp 00000000 08:03 1032259 /usr/lib/libXinerama.so.1.0.0
b70eb000-b70ec000 rw-p 00001000 08:03 1032259 /usr/lib/libXinerama.so.1.0.0
b70ec000-b70f4000 r-xp 00000000 08:03 1032243 /usr/lib/libXcursor.so.1.0.2
b70f4000-b70f5000 rw-p 00007000 08:03 1032243 /usr/lib/libXcursor.so.1.0.2
b70f5000-b70f9000 r-xp 00000000 08:03 5051904 /usr/lib/libXfixes.so.3.1.0
b70f9000-b70fa000 rw-p 00003000 08:03 5051904 /usr/lib/libXfixes.so.3.1.0
[stack]
and so on
It's not a memory leak. You must have made a mistake in your code...
Here is something that works for me:
Qt Code:
#include <QApplication> #include <QAbstractListModel> #include <QListView> #include <QList> #include <QHash> #include <QTimerEvent> public: void add(int id){ if(m_hash.contains(id)){ int row = m_hash[id]; m_data[row].count++; emit dataChanged(index(row), index(row)); } else { int row = m_data.count(); S s; s.id = id; s.count = 1; m_data.append(s); m_hash[id] = row; endInsertRows(); } } int columnCount(const QModelIndex&) const { return 1; } if(role!=Qt::DisplayRole || !hasIndex(index.row(), index.column(), index.parent())) int row = index.row(); } void start(){ m_tid = startTimer(100); } protected: if(e->timerId()==m_tid){ int id = qrand() % 20; add(id); } else } private: struct S { int id; int count; S(){id=-1;count=1;} }; QList<S> m_data; QHash<int, int> m_hash; int m_tid; }; int main(int argc, char **argv){ Model m; QListView lv; lv.setModel(&m); m.start(); lv.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
I went through my code milion times...
Thanks buddy...Ill take a look at yours and try to find a mistake...
so...I remade my codes...now they compile OK...and my app doesnt exit with the code as above...but the statistics dont get actualized ...even when I emit dataChanged() signal when the data get updated...but they still dont...
I slowly but surely give up...
Qt Code:
{ Q_UNUSED(parent); return idStatsList.count(); } { Q_UNUSED(parent); return 2; } { if(orientation == Qt::Horizontal){ if(role == Qt::DisplayRole){ switch(section){ case 0 : return tr("ID"); break; case 1 : return tr("Count"); break; case 2 : return tr("Comment"); break; default : break; } } } return ret; } { QVariant ret; if(!index.isValid()){ std::cout <<"Invalid Index of data provided!"<< std::endl; return ret; } int row = index.row(); int col = index.column(); if(row >= 0 && row < rowCount()) { if(role == Qt::DisplayRole) { switch(col) { case 0 : ret = idStatsList[row].id; break; case 1 : ret = idStatsList[row].count; break; case 2 : //ret = item.comments; break; default : break; } } } return ret; } //SLOT catching new arriving messages void MsgStatsModel::updateStats(const QVcaCanMsg &canmsg) { int id = canmsg.id(); if(indexHash.contains(id)){ int row = indexHash[id]; idStatsList[row].count++; emit dataChanged(index(row, 0), index(row, 0)); } else { int row = idStatsList.count(); StatsItem item; item.id = id; item.count = 1; idStatsList.append(item); indexHash[id] = row; endInsertRows(); } }To copy to clipboard, switch view to plain text mode
something is wrong...but cant figure out what...statistics get stored CORRECTLY...count is incremented nicely even for different ids...the problem is display in TableView...![]()
If you have three columns, I suggest you emit it like:Qt Code:
emit dataChanged(index(row, 0), index(row, 0));To copy to clipboard, switch view to plain text mode
Qt Code:
emit dataChanged(index(row, 0), index(row, 2));To copy to clipboard, switch view to plain text mode
If you emit changes only in the first column, nothing gets updated, because your count is in the second column, so the correct version is:
Qt Code:
emit dataChanged(index(row, 1), index(row, 1));To copy to clipboard, switch view to plain text mode
gyre (10th December 2007)
Bookmarks