Results 1 to 11 of 11

Thread: how to download images using URL link

  1. #1
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to download images using URL link

    i have link which contains image..i have to download this image using Qt.i have tried bt i dont get to download..
    can any one give me suggestion for this
    Thanks in Advance
    below code which i tried so far:


    Qt Code:
    1. QUrl url1("http://103.3.229.181/digital-photo-frame-ads\/public/uploads/07032015/qzms7p5nfcza55539.jpg");
    2. QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    3. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(netwManagerFinished(QNetworkReply*)));
    4. QNetworkRequest request(url1);
    5. manager->get(request);
    6.  
    7.  
    8. void Widget::netwManagerFinished(QNetworkReply *reply)
    9. {
    10. QByteArray jpegData = pic.toLocal8Bit();
    11. QPixmap pixmap;
    12. pixmap.loadFromData(jpegData);
    13. QPixmap scaled = pixmap.scaled(128,64,Qt::IgnoreAspectRatio, Qt::FastTransformation);
    14. l.setPixmap(scaled);
    15. l.show();
    16. QString filename = QFileDialog::getSaveFileName(this, tr("Save Skin"), "/home/ihorse1/10-03-2015", ,tr("JPEG Image(*.jpg)"));
    17. QFile file (filename);
    18. file.open(QIODevice::WriteOnly);
    19. QDataStream out (&file);
    20. out << reply;
    21. qDebug()<<out;
    22. file.close();
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 9th March 2015 at 07:41. Reason: changed [quote] to [code]

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to download images using URL link

    Where do you read the reply data?

    I would expect to see a reply->readAll() in your netwManagerFinished slot that reads the data retrieved by the get request. You should also check the http status code when the request is finished.

    Lastly, please use the [code][/code] tags when posting your code, not [quote][/quote] tags.

  3. #3
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to download images using URL link

    i made changes sir,,
    bt i got an arror as
    QPixmap::scaled: Pixmap is a null pixmap
    QFSFileEngine:pen: No file name specified
    QIODevice:utChar: Closed device
    QVariant(, )
    QPixmap::scaled: Pixmap is a null pixmap
    QFSFileEngine:pen: No file name specified
    QIODevice:utChar: Closed device
    QVariant(, )
    my code below:
    Qt Code:
    1. QUrl url("http://103.3.229.181/digital-photo-frame-ads/public/getImages");//this link contains two images
    2. QNetworkAccessManager manager;
    3. QNetworkReply *response = manager.get(QNetworkRequest(QUrl(url)));
    4. QEventLoop event;
    5. connect(response,SIGNAL(finished()),&event,SLOT(quit()));
    6. event.exec();
    7. QString html = response->readAll();
    8. if(html.length() > 0){
    9. str = html.split(",");
    10. for (int i = 0; i < str.size(); ++i)
    11. {
    12. pic=pic.remove(QRegExp(QString::fromUtf8("[`~!@#$%^&*()_—+=|;<>«»,?{}\'\"\\\[\\\]\\\\]")));
    13. QByteArray jpegData = pic.toLocal8Bit();
    14. QPixmap pixmap;
    15. pixmap.loadFromData(jpegData);
    16. QPixmap scaled = pixmap.scaled(128,64,Qt::IgnoreAspectRatio, Qt::FastTransformation);
    17. l.setPixmap(scaled);
    18. l.show();
    19. QString filename = QFileDialog::getSaveFileName(this, tr("Save Skin"), "/home/ihorse1/10-03-2015",tr("JPEG Image(*.jpg)"));
    20. QFile file (filename);
    21. file.open(QIODevice::WriteOnly);
    22. QDataStream out (&file);
    23. out << reply;
    24. qDebug()<<out;
    25. file.close();
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by jthomps View Post
    Where do you read the reply data?

    I would expect to see a reply->readAll() in your netwManagerFinished slot that reads the data retrieved by the get request. You should also check the http status code when the request is finished.

    Lastly, please use the [code][/code] tags when posting your code, not tags.

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to download images using URL link

    Line 14 makes no sense at all. Are your loading a URL into the QByteArray expecting it to contain the actual image data? Everything after that will fail because your QByteArray doesn't contain valid image data, so obviously line 16 will fail also.

    I suggest that you start over and try to successfully get a single URL that contains image data and go from there. Use QNetworkAccessManager->get() to issue the http request for the actual image, then in your slot connected to finished(), reply->readAll() the data into a QByteArray. Once you have done that successfully, then you can try to create your QPixmap and write image data to a file, etc.

    What you just posted now is different than your first post (and you also have a similar post earlier in this same forum). You make it very hard for someone to help you because of your shotgun approach to posting wildly different non-compilable and non-functional code each time you post.

    Good luck to you.

    BTW, wysota already stated in your other thread on this topic that your data is apparently in JSON format. If you process this using the QJson* classes, you won't have to jump through all of the hoops you are currently attempting with the returned URLs.

  5. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (9th March 2015)

  6. #5
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to download images using URL link

    how to implement JSON format ..give some example

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to download images using URL link

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    iswaryasenthilkumar (9th March 2015)

  9. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: how to download images using URL link

    The Qt JSON documentation contains examples, so please read the documentation for QJsonDocument, QJsonObject, QJsonArray, etc.

    Additional documentation is available here and here and of course there is always google.

  10. The following user says thank you to jefftee for this useful post:

    iswaryasenthilkumar (9th March 2015)

  11. #8
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to download images using URL link

    i have one doubt which method is used to download images by url in qt

  12. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to download images using URL link

    QNetworkAccessManager::get()

    Cheers,
    _

  13. The following user says thank you to anda_skoa for this useful post:

    iswaryasenthilkumar (9th March 2015)

  14. #10
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to download images using URL link

    i have one more doubt
    http://103.3.229.181/digital-photo-f...vz23l90653.jpg
    based on the above link i need to get only wqpc0ffvz23l90653.jpg what method is used to get this input,,pls give me suggestion for this
    Thanks in advance

  15. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to download images using URL link

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. The following user says thank you to wysota for this useful post:

    iswaryasenthilkumar (10th March 2015)

Similar Threads

  1. how to use QNetworkAccessManager to download images in QT
    By iswaryasenthilkumar in forum Newbie
    Replies: 5
    Last Post: 6th March 2015, 09:54
  2. Replies: 1
    Last Post: 5th October 2012, 11:08
  3. Qhttp Get file size in Link download
    By nhs_0702 in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2010, 09:24
  4. How to open download link with WebKit
    By myrky in forum Newbie
    Replies: 1
    Last Post: 9th July 2009, 07:11
  5. QTWebKit unable to load download link
    By myrky in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2009, 07:09

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.