Results 1 to 6 of 6

Thread: Multiple QNetworkRequest slows the GUI performance

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2017
    Posts
    8
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Multiple QNetworkRequest slows the GUI performance

    Hello,
    I am writing an application and I am requesting RestApi for multiple data via different URLs.
    From the Mainwindow, I set a timer and call the functions for every one second. I have many functions like getData and I get the reply properly. But the response time is slow and the application itself is slow now. Even clicked on GUI Menu response time is slow. Am I doing anything wrong here?


    Qt Code:
    1. //In MainWindow.cpp
    2. void MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),UI(new Ui::MainWindow)
    3. {
    4. ui->setupUi(this);
    5. Api *ap = new Api(this);
    6. }
    7. void MainWindow::updateValues()
    8. {
    9. QTimer* timer=new QTimer(this);
    10. connect(timer, SIGNAL(timeout()), this, SLOT(findUpdate()));
    11. timer->start(1000);
    12. }
    13. //I call multiple functions from api
    14. void MainWindow::findUpdate()
    15. {
    16.  
    17. api->getData(url);
    18. api->getData1(url);
    19. }
    20.  
    21. //In api.h file QNetworkAcessManager manager;
    22. //In api.cpp
    23. void Api::getData(QString url)
    24. {
    25. QNetworkRequest request(QUrl(url));
    26. QNetworkReply *reply = manager.get(request);
    27. connect(reply,SIGNAL(finished()),this,SLOT(replydata()));
    28. }
    29. void Api::replyData()
    30. {
    31. QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
    32. if(reply)
    33. {
    34. QString response = (QString)reply.realAll();
    35. QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
    36. list = json.array();
    37. delete reply;
    38. }
    39. else
    40. {
    41. qDebug() << "Failure" << reply->errorString();
    42. delete reply;
    43. }
    44. emit listOfValues(list);
    45. }
    46.  
    47. void Api::getData1(QString url)
    48. {
    49. QNetworkRequest request(QUrl(url));
    50. QNetworkReply *reply = manager.get(request);
    51. connect(reply,SIGNAL(finished()),this,SLOT(replydata1()));
    52. }
    53. void Api::replyData1()
    54. {
    55. QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
    56. if(reply)
    57. {
    58. QString response = (QString)reply.realAll();
    59. QJsonDocument json = QJsonDocument::fromJson(response.toUtf8());
    60. list = json.object();
    61. delete reply;
    62. }
    63. else
    64. {
    65. qDebug() << "Failure" << reply->errorString();
    66. delete reply;
    67. }
    68. emit listOfValues(list);
    69. }
    To copy to clipboard, switch view to plain text mode 
    d

    Thanks in advance,
    Deepikha
    Last edited by deepikha; 20th October 2020 at 11:55.

Similar Threads

  1. Performance issues with multiple visible Windows
    By Zmote89 in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2017, 20:20
  2. Multiple QGLWidgets performance issue
    By louissmr in forum Qt Programming
    Replies: 0
    Last Post: 18th July 2013, 09:28
  3. Multiple QGLWidgets slow performance
    By seesomi in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2013, 10:20
  4. Replies: 1
    Last Post: 14th April 2011, 16:21
  5. rendering svg using QGraphicsSVGItem slows doen the performance
    By sanjayshelke in forum Qt Programming
    Replies: 4
    Last Post: 1st September 2009, 07:52

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.