Page 2 of 2 FirstFirst 12
Results 21 to 21 of 21

Thread: Simplest app with QNetworkAccessManager and First-chance exception

  1. #21
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Simplest app with QNetworkAccessManager and First-chance exception

    Different back trace but have the same result,

    For test this case, I create a new Visual Studio project, and my test code list below. May be someone can test this code

    Qt Code:
    1. //test.h
    2. #ifndef TEST_H
    3. #define TEST_H
    4.  
    5. #include <QtWidgets/QMainWindow>
    6. #include <QtNetwork>
    7. #include "ui_test.h"
    8.  
    9.  
    10. class Test : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. Test(QWidget *parent = 0);
    16. ~Test();
    17.  
    18. public slots:
    19. void Button_clicked();
    20. void destroy_clicked();
    21. void Request_finished(QNetworkReply *reply);
    22.  
    23. private:
    24. Ui::TestClass ui;
    25. QNetworkReply* reply;
    26. QNetworkAccessManager* manager;
    27. };
    28.  
    29. #endif // TEST_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //test.cpp
    2. #include "test.h"
    3. #include <QtWidgets>
    4.  
    5. Test::Test(QWidget *parent)
    6. : QMainWindow(parent)
    7. {
    8. ui.setupUi(this);
    9. QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(Button_clicked()));
    10. QObject::connect(ui.btn_destroy, SIGNAL(clicked()), this, SLOT(destroy_clicked()));
    11.  
    12. reply = NULL;
    13. manager = NULL;
    14. }
    15.  
    16. Test::~Test()
    17. {
    18. }
    19.  
    20. void Test::Request_finished(QNetworkReply *reply)
    21. {
    22. //reply->deleteLater();
    23. }
    24.  
    25. void Test::Button_clicked()
    26. {
    27. manager = new QNetworkAccessManager(this);
    28. QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(Request_finished(QNetworkReply *)));
    29. QNetworkRequest request(QUrl("http://www.google.com"));
    30. reply = manager->get(request);
    31. }
    32.  
    33. void Test::destroy_clicked()
    34. {
    35. qDebug() << "to delete reply...";
    36. if (reply)
    37. {
    38. reply->abort();
    39. delete reply;//->deleteLater();
    40. reply = NULL;
    41. }
    42.  
    43. qDebug() << "to delete manager...";
    44. if (manager)
    45. {
    46. delete manager;
    47. manager = NULL;
    48. }
    49.  
    50. qDebug() << "reply, manager destroyed...";
    51. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 5th September 2013 at 21:34. Reason: missing [code] tags

Similar Threads

  1. Simplest example for QGraphicsPixmapItem
    By sincnarf in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2012, 14:24
  2. Simplest SQL example
    By janus66 in forum Newbie
    Replies: 3
    Last Post: 21st July 2011, 07:40
  3. the simplest custom slot
    By tommy in forum Qt Programming
    Replies: 30
    Last Post: 12th November 2007, 11:18
  4. simplest / best way to fuse several files with QT?
    By Havard in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2007, 10:06
  5. A simplest ListModel... no example :(
    By tomek in forum Newbie
    Replies: 5
    Last Post: 7th January 2006, 00:32

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
  •  
Qt is a trademark of The Qt Company.