I'm making a program to present the user (me) with a list of filenames and the option to do a few things to them. But I'm still only at the point of just testing how QListView works. It ought to be really simple, but it's crashing and I'm stuck.
I don't even know where exactly it crashes; it's after the app exec(). I think maybe some object is being destroyed, and later accessed, but I don't understand Qt very well. As for some guesses: I read that QListView doesn't take ownership of models, but it still crashes if QStringListModel is initialized with any parent. I'm not using QModelIndex yet so it can't be due do to sloppy use of one of those.
The program happens to segfault in QTextEngine's itemize(). It won't crash if some statements are switched around, or if the strings have very slightly different contents, or if a messagebox is exec() before dialog.show(), etc. However, I assume those are coincidences related to how memory is laid out, or timing.
What am I doing wrong? I'm out of ideas.
It's Qt 4.7.0 on linux. Problem also happens with Qt 4.7.2.
#include <QtGui>
#include <QtGlobal>
int main(int argc, char *argv[])
{
QLabel label
("label of stuff");
list.
append(QString("The cat he"));
model.setStringList(list);
view.setModel(&model);
dialog.setLayout(&layout);
layout.addWidget(&label);
dialog.show(); // if this happens here it crashes
layout.addWidget(&view);
//dialog.show(); // if this instead happens here it's "stable"
return a.exec();
}
#include <QtGui>
#include <QtGlobal>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog dialog;
QVBoxLayout layout;
QLabel label("label of stuff");
QListView view;
QStringListModel model;
QStringList list;
list.append(QString("hello"));
list.append(QString("The cat he"));
model.setStringList(list);
view.setModel(&model);
dialog.setLayout(&layout);
layout.addWidget(&label);
dialog.show(); // if this happens here it crashes
layout.addWidget(&view);
//dialog.show(); // if this instead happens here it's "stable"
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks