View Full Version : How to parse the image from the server and display it in the Listwidget?

6th December 2011, 10:14
I am trying to parse the image from the server and display it in a QListWidget.

I am having the image in an array as a QString.I had tried to convert the image into QBytearray and then parse that value for displaying the image but it not works.

This is the code which i had tried:

QString Image = image[i];
QByteArray u;

ui->listWidget->addItem(new QListWidgetItem(QIcon(Image),Name,ui->listWidget));

It just displays the listwidget and not the image.When i tried using QString it displays the URL of the image and not the image.

Can anyone help me to know where i was wrong.Is there anyone any additional code to be included?

Anyone come with the answer..

Thanks in advance,

7th December 2011, 00:33
The binary data of an image is not a string of characters so it make absolutely no sense to put it in a QString, which will almost certainly mangle the image. You than append that mangled data to a byte array that you never use again. When you try to convert the original mangled image data into a QIcon you get a null icon, which is what you see.

If the thing you are starting with is a URL pointing at a resource somewhere on the Internet then you don't have an image at all. You need to retrieve the image before you can do anything with it.

7th December 2011, 06:04
Ok Chris Could you help me with the code?

7th December 2011, 07:05
Not unless you tell us what you are starting with. The few lines you have posted are not sufficient for us to know what you actually have as input.

7th December 2011, 10:41
void screen::content(QList<QString> name,QList<QString> category,QList<QString> image)
QListWidget *list = new QListWidget(0);

QStringList strList;
for(int i=0 ; i<name.count(); i++)
QString Name = name[i];
QString Image = image[i];

QNetworkAccessManager *nam = new QNetworkAccessManager(this);
connect(nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(finished(QNetworkReply*)));
QByteArray myData("image");

QString f = Name ;

ui->listWidget->addItem(new QListWidgetItem(QIcon("reply"),f,ui->listWidget));


voidscreen::replyFinished(QNetworkReply *reply)

This is my code in which i am trying to parse the image from the server.I dont know how to parse the image into the listwidget i had tried this level.Help me out to get the answer?