Results 1 to 5 of 5

Thread: How to parse the image from the server and display it in the Listwidget?

  1. #1
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post How to parse the image from the server and display it in the Listwidget?

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to parse the image from the server and display it in the Listwidget?

    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.

  3. #3
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to parse the image from the server and display it in the Listwidget?

    Ok Chris Could you help me with the code?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to parse the image from the server and display it in the Listwidget?

    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.

  5. #5
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post Re: How to parse the image from the server and display it in the Listwidget?

    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
    Last edited by harish; 7th December 2011 at 09:43. Reason: spelling corrections

Similar Threads

  1. Replies: 1
    Last Post: 24th August 2011, 14:09
  2. Parse RSS into html and display it in QWebView.
    By halvors in forum Qt Programming
    Replies: 11
    Last Post: 14th August 2010, 12:44
  3. how to parse xml with a image using qt?
    By bezlew in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2009, 09:04
  4. systray: icon does not display in windows server 2003
    By lovelypp in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2008, 10:47
  5. Display a QWidget on two X-Server at the same time
    By tarod in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2008, 12:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.