PDA

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



harish
6th December 2011, 10:14
Hi,
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;
u.append(Image);



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,
Harish.M

ChrisW67
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.

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

ChrisW67
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.

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

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");
nam->post(QNetworkRequest(QUrl("image")),myData);



QString f = Name ;

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


}
this->showFullScreen();
}

voidscreen::replyFinished(QNetworkReply *reply)
{
reply->readAll();
}


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?

Regards,
Harish.M