PDA

View Full Version : display an array of integers



rafik
4th February 2016, 18:05
Hello,
i want to display an array of integers, how can i do that please?
Thank you.

anda_skoa
4th February 2016, 18:20
There are so many ways that you will need to be a bit more precise on what you need.

Cheers,
_

rafik
4th February 2016, 18:28
i want to code a merge sort algorithm, but just to start i want to display for example a QVector of 10 elements, just for the interface
i want to display this vector


#include <QApplication>
#include <QtWidgets>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget f;
QVector<int> vector(5);
for (int i=0;i< vector.size(); i++)
{
vector[i]=i;
}




f.show();
return app.exec();

}

anda_skoa
4th February 2016, 19:40
The easiest way I can think of is to create a string that contains all numbers and display that in a QLabel


QStringList items;
foreach (const int number, vector) {
items << QString::number(number);
}
label->setText(items.join(", "));


Alternatively with a QListWidget


foreach (const int number, vector) {
listWidget->addItem(QString::number(number));
}


Cheers,
_

rafik
6th February 2016, 19:16
Thank you Mr anda, with your second example QListWidget i get what i want. thanks :)