first of all this is quite weird to me (I'd rather use QStandardItemModel as member variable):
class MainWindow : public QMainWindow, QStandardItemModel
To copy to clipboard, switch view to plain text mode
but this way it can maybe work too... But:
MainWindow
::MainWindow(QWidget *parent
){
ui->setupUi(this);
setVisible(true); // 1
qDebug() << " list view";
Tweet *tweet = new Tweet(); // 2
for (int i = 0; i < 24; i++ ) {
tweet->resize( ui->listWidget->width() , tweet->height() );
item(i)->setSizeHint(tweet->size()); // 3
ui->listWidget->setIndexWidget(item(i)->index(),tweet); // 4
}
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindowClass)
{
ui->setupUi(this);
setVisible(true); // 1
qDebug() << " list view";
Tweet *tweet = new Tweet(); // 2
for (int i = 0; i < 24; i++ ) {
tweet->resize( ui->listWidget->width() , tweet->height() );
item(i)->setSizeHint(tweet->size()); // 3
ui->listWidget->setIndexWidget(item(i)->index(),tweet); // 4
}
}
To copy to clipboard, switch view to plain text mode
this constructor it's problem in your case. And your problem is not that it's not showing frame, but it's crashing because of segmentation fault!. And segmentation fault is commonly the error caused by bad code - means you can't write it in way it can work (and it is n C and C++, Qt don't do seg faults by itself) - back to the old story - learn some C++...
But ok, I can explain your errors.
In line marked as "// 1" you are calling setVisible(true); it's not an error maube but you are also calling show in main() finction which shows your main window - and that the way it should be, so just delete that line.
In line marked as "// 2" - you created a Tweet, but it's just one Tweet. You want to have 24 same Tweets in list?
Ok, and now you start for loop. Tell me how many items is in your model at the start of the for loop? Don't guess. You can check it easily. You don't event have to check it. Just think for a moment and please post how many items is in your model at the start of the for loop? And wysota asked you for it once and it was few days ago so maybe you found any way to do that in those days.
When you found the answer, then try to tell me what happens in line marked as "// 3".
If it's to difficult for you to open the Assistant (usually typing "assistant" in run command window (shortcut: WinLogo + R) is enough to run it) and searching there something about QStandardItemModel you can just click on this link: QStandardItemModel::item() and read the only sentence there about that method.
Finally, tell me also how many time the line "// 4" is reached/executed in your application?
Good luck in answers searching!
Bookmarks