Results 1 to 1 of 1

Thread: QNetworkAccessManager doesn't call QNetworkReply

  1. #1
    Join Date
    Jul 2021
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default QNetworkAccessManager doesn't call QNetworkReply

    So i made a program that connects to Youtube, downloads the page and parses for video title and tags. It works fine for 5-6 times the request is being called, but then the functionality of the youtube class stops, and processor usage rises to 12% and stays at this level. This is my code

    Qt Code:
    1. #include "youtube.h"
    2. #include <QByteArray>
    3. #include <QNetworkCookieJar>
    4. #include "youtube.h"
    5.  
    6. Youtube::Youtube(QObject *parent)
    7. {
    8. manager = new QNetworkAccessManager(this);
    9. manager->setCookieJar(this);
    10. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotReadyRead(QNetworkReply*)));
    11.  
    12. auto aName = manager->objectName();
    13. connect(manager, &QNetworkAccessManager::encrypted,
    14. this, [aName]{ qDebug()<< "connect - encrypted"; });
    15. }
    16.  
    17. void Youtube::makeRequest(QString indexCore)
    18. {
    19. youtubeActive_is = true;
    20. url = "https://" + indexCore;
    21. QUrl urlForCookies (url);
    22.  
    23. request.setRawHeader("COOKIE" , "CONSENT=YES+42"); //works
    24. request.setUrl(urlForCookies);
    25. manager->get(request);
    26. }
    27.  
    28.  
    29. void Youtube::slotReadyRead(QNetworkReply *replay)
    30. {
    31. QByteArray dataTemp = replay->readAll();
    32. website = dataTemp.toStdString();
    33.  
    34. if(website.size()!=0)
    35. {
    36. Parser parser;
    37. std::string title = parser.extract_tagContent(website, "title");
    38.  
    39. title = "\u00034" +title;
    40. postToIRC(title);
    41.  
    42. youtubeActive_is = false;
    43. }
    44.  
    45.  
    46. manager->autoDeleteReplies();
    47. manager->clearAccessCache();
    48. manager->clearConnectionCache();
    49.  
    50. replay->abort();
    51. replay->close();
    52. replay->deleteLater();
    53.  
    54. for (int i = 0; i < allCookies().size(); ++i) {
    55. manager->cookieJar()->deleteCookie(allCookies().at(i));
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 5th October 2021 at 03:22. Reason: missing [code] tags

Similar Threads

  1. Replies: 1
    Last Post: 28th September 2015, 14:47
  2. Replies: 7
    Last Post: 14th November 2014, 17:29
  3. Replies: 0
    Last Post: 15th January 2014, 17:15
  4. QNetworkAccessManager and multiple QNetworkReply
    By Acid in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2012, 23:52
  5. Replies: 2
    Last Post: 18th June 2010, 12:04

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.