I think QListWidget class is a better solution instead of a QList<QLabel*> and it doesn't complicate the code that much.
Nevertheless, because it seems to me you are a beginner in C++, i have some advice: learn C++ before Qt, at least until you know OOP in C++ and you have a pretty good understanding of pointers and memory management, else Qt might seem very "unfriendly", and it's not like that Qt is very easy to use, but because it's a C++ framework it requires some C++ knowledge.
Anyway here is a little example code that uses QListWidget:
#include <QApplication>
#include <QListWidget>
#include <QHBoxLayout>
#include <QListWidget>
int main(int argc, char** argv)
{
//QListWidget is a convenience class
//usefull to quickly show a list and you don't need to complicate your life with MV
// alternative for QList<QString>,
// is actually derived from QList<QString>
// and it implements some methods that might be usefull - example join
//add some items into the QStringList
//here i use the operator<<, but it has other methods like append... see the documentation
listOfStrings << "item 0" << "item 1" << "item 2";
//add the items from the QStringList
listWidget->addItems(listOfStrings);
layout->addWidget(listWidget);
w.show();
return a.exec();
}
#include <QApplication>
#include <QListWidget>
#include <QHBoxLayout>
#include <QListWidget>
int main(int argc, char** argv)
{
QApplication a(argc,argv);
QWidget w;
QHBoxLayout* layout = new QHBoxLayout(&w);
//QListWidget is a convenience class
//usefull to quickly show a list and you don't need to complicate your life with MV
QListWidget* listWidget = new QListWidget();
// alternative for QList<QString>,
// is actually derived from QList<QString>
// and it implements some methods that might be usefull - example join
QStringList listOfStrings;
//add some items into the QStringList
//here i use the operator<<, but it has other methods like append... see the documentation
listOfStrings << "item 0" << "item 1" << "item 2";
//add the items from the QStringList
listWidget->addItems(listOfStrings);
layout->addWidget(listWidget);
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Further reading Model/View
Bookmarks