Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    1. Home
    2. Tags
    3. qnetworkaccessm
    Log in to post

    • SOLVED Correct code to prevent memory leak with QNAM HTTP Get request to nonexistent URL with Qt 5.14.2
      General and Desktop • qnetworkaccessm qt5.14.2 timeout http get qnam • • WilliamJ  

      5
      0
      Votes
      5
      Posts
      27
      Views

      Thank you Christian! https://bugreports.qt.io/browse/QTBUG-88063 describes exactly what I've been seeing.
    • UNSOLVED Login and save session to navigate to other pages
      General and Desktop • qnetworkaccessm qnetworkreply qnetworkrequest qnetworkcookiej qurlquery • • najihahnizar  

      1
      0
      Votes
      1
      Posts
      37
      Views

      No one has replied

    • SOLVED How to initialize a QNetworkAccessManager properly
      General and Desktop • qnetworkaccessm • • Aymeric_Qt  

      3
      0
      Votes
      3
      Posts
      66
      Views

      Hello SGaist, Thank you very much for your answer. I was sure I've already tried to make it a member variable of the class and having some error. Not a the compilation but when I tried to launch the app (app was ended forcefully as the messages read). I had to make a mistake at the time but I can remmber I've done differently. Anyway now it's working, thank you!
    • UNSOLVED Compare QUrl or slot for each response?
      Qt WebKit • qnetworkaccessm c++11 signals & slots qurl restful api • • Rizwan94  

      4
      0
      Votes
      4
      Posts
      132
      Views

      @Rizwan94 I never used QNAM, so do not know whether better to use that one or QNetworkReply Yes
    • UNSOLVED For Rest API calls, use QNAM or restsdk
      Qt WebKit • qnetworkaccessm c++11 restful api restsdk • • Rizwan94  

      2
      0
      Votes
      2
      Posts
      160
      Views

      Hi, You have to do some testing to see which one works best for you. Since you are using Qt, QNAM asynchronous nature follows Qt design and what you are used to.
    • SOLVED When qnetworkreply is delete after request from QNetworkAccessManager::get(QNetworkRequest request (url))?
      General and Desktop • qnetworkaccessm qnetworkreply qnetworkrequest qnetwork • • Yash001  

      2
      0
      Votes
      2
      Posts
      60
      Views

      Hi, Usually you don't store the reply but rather connect its signals to lambdas, do the processing there and then call deleteLater on it once you are done.
    • UNSOLVED QSocketNotifier Exception After Deletion of QNetworkAccessManager Object
      General and Desktop • qnetworkaccessm qnetworkreply qnetworkrequest qsocketnotifier • • Zach M  

      10
      0
      Votes
      10
      Posts
      344
      Views

      Ahh sorry I thought an strace would help. It might take me a bit to get an actual stack trace as I'd have to set up my build environment with debugging symbols. The reason I was recreating QNetworkAccessManager is because I was under the impression that I needed to do so when I lost network access (m_mgr->networkAccessible() != QNetworkAccessManager::Accessible). That's what a user said on this stack overflow post. Is that incorrect? If I could just used something like setNetworkAccessible() that would avoid this whole mess. I've tested out removing the QNAM deletion and the exception does not occur. I guess I am sort of confused in general about what QNetworkAccessManager::NetworkAccessibility even represents? It's not going to alter the actual network state, NetworkManager handles that
    • SOLVED uploadProgress signal emitted 0/0 with long delay
      General and Desktop • qnetworkaccessm qnetworkreply qnetworkrequest upload • • yasen  

      7
      0
      Votes
      7
      Posts
      484
      Views

      Tested on another server, everything works fine
    • SOLVED QNetworkAccessManager seems to leak with every retry
      General and Desktop • qnetworkaccessm memory networking • • Smaankers  

      10
      0
      Votes
      10
      Posts
      1040
      Views

      Okay I found the culprit in an unexpected corner. I decided to completely strip it to the absolute bare minimum: int main(int argc, char *argv[]) { QCoreApplication app (argc, argv); // initialization Sms_notifier notifier(true, 5); notifier.notify( "+0123456789", "Lorem Ipsum is simply dummy text of the printing and typesetting industry. "); qWarning() << "done, looping"; while(true) { QCoreApplication::exec(); } } Sms_notifier::Sms_notifier(bool test, int interval_length_milliseconds) : QObject (NULL) ,m_test (test) ,m_interval_length_milliseconds(interval_length_milliseconds) ,m_manager () ,m_timer () ,m_addressee() ,m_payload() { m_timer.setSingleShot(true); QObject::connect(&m_manager, &QNetworkAccessManager::finished, this, &Sms_notifier::on_nam_finished); QObject::connect(&m_timer, &QTimer::timeout, this, &Sms_notifier::on_timer_elapsed); } Sms_notifier::~Sms_notifier() { } bool Sms_notifier::notify( const std::string addressee, const std::string payload ) { m_addressee = addressee; m_payload = payload; return notify(); } bool Sms_notifier::notify() { QNetworkRequest request; QByteArray data; m_manager.post(request, data); return false; } void Sms_notifier::on_nam_finished(QNetworkReply* reply) { QNetworkReply::NetworkError error = reply->error(); reply->deleteLater(); if (error != QNetworkReply::NetworkError::NoError) { m_timer.start(m_interval_length_milliseconds); } else { qWarning() << "success"; m_addressee.clear(); m_payload.clear(); } } void Sms_notifier::on_timer_elapsed() { notify(); } It turns out it was still leaking while there was no network. So I stripped away all libraries that were linked, and it still leaked. Eventually my eye struck this in the .pro file: QMAKE_CXXFLAGS += -fsanitize=address QMAKE_CFLAGS += -fsanitize=address QMAKE_LFLAGS += -fsanitize=address -lasan This was added to detect memory leaks and report them when the application quits. After removing this, the excessive "memory leak" was gone. I am assuming that the address sanitizer allocates memory for each allocation done by the application, for its own administration purposes. I suspect that when the application releases the allocated memory, the sanitizer holds on to the respective administration data until the application quits. This could explain why when I remove the sanitizer it also removes the leak. Well, thanks everyone for your input!
    • UNSOLVED How to properly handle asynchronous events with Qt test framework? QSignalSpy::wait() returns false even though signal emitted during given time interval
      General and Desktop • qnetworkaccessm qnetworkreply qtest qtestlib qsignalspy • • Red Baron  

      3
      0
      Votes
      3
      Posts
      1929
      Views

      Thanks for the reply. Will check it out.
    • UNSOLVED QNetworkAccessManager and Python http server
      General and Desktop • python qnetworkaccessm • • umod.47  

      3
      1
      Votes
      3
      Posts
      1137
      Views

      There's nothing wrong with GET request, since it has no payload, just a header. Problems begin with POST. Server side is pretty simple, with one exception: it sends HTTP reply header ASAP and THEN launches CGI script. Here is a Wireshark dump of an interconnection with python server: http://umod47.ru/qtfail.pcapng
    • UNSOLVED QNetworkAccessManager purges cookies if following redirect
      General and Desktop • qnetworkaccessm qtnetwork redirect cookies • • Jiloc  

      8
      0
      Votes
      8
      Posts
      2398
      Views

      @raven-worx I did as you suggested https://bugreports.qt.io/browse/QTBUG-63313 . Hope the bug report is properly documented
    • MDTM:Command not understood
      General and Desktop • qnetworkaccessm ftp • • Rohith  

      3
      0
      Votes
      3
      Posts
      894
      Views

      @jsulm said in MDTM:Command not understood: ftp://115.111.229.10/21.05.2016.xls Thanks for replying, yes the url is working fine with wget wget ftp://username:password@(IP)/21.05.2016.xls
    • UNSOLVED How to send QString to server in Qt 5.6?
      QtWebEngine • network qnetworkaccessm qnetworkreply qnetworkrequest • • d1.psy  

      7
      0
      Votes
      7
      Posts
      1991
      Views

      @d1.psy so you want the cookies from the requests you already made with QtWebEngine? If so take a look at QWebEngineCookieStore (see it's signals) and "sync" the cookies into your QNAM.
    • UNSOLVED Android QNetworkAccessManager in background
      Mobile and Embedded • android qnetworkaccessm • • dead_man  

      2
      0
      Votes
      2
      Posts
      655
      Views

      I resolved my problem by moving request object to main thread
    • SOLVED can't get JSON file from QNetworkReply
      General and Desktop • qnetworkaccessm json qwebengineview qnetworkrequest qnetreply • • nazimGT  

      2
      0
      Votes
      2
      Posts
      3581
      Views

      resolved !! i've chenged m_pNetworkAccessManager->get(request); by request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QByteArray par=""; m_pNetworkAccessManager->post(request,par);
    • UNSOLVED How to find complete information about the file to be downloaded using QNetworkAccessManager HTTP Qt
      General and Desktop • network qnetworkaccessm file http download • • Farhan  

      2
      0
      Votes
      2
      Posts
      1296
      Views

      The server is not returning anything useful in the HTTP headers (I wouldn't expect it to): ~/tmp$ wget -S 'http://u801.wapkafile.com//g03/video/1253022/7940/c8f9a32ef15648bfa6f693102de27835/DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610' --2016-07-27 18:21:15-- http://u801.wapkafile.com//g03/video/1253022/7940/c8f9a32ef15648bfa6f693102de27835/DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610 Resolving u801.wapkafile.com (u801.wapkafile.com)... 8.37.229.38 Connecting to u801.wapkafile.com (u801.wapkafile.com)|8.37.229.38|:80... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: nginx Date: Wed, 27 Jul 2016 08:21:15 GMT Content-Type: video/x-msvideo Content-Length: 65707724 Connection: keep-alive Last-Modified: Wed, 31 Dec 2014 06:15:08 GMT Content-Disposition: attachment; filename="DARNA-ZAROORI-HAI-3(Movies7.In).avi" Accept-Ranges: bytes Expires: Wed, 03 Aug 2016 06:34:10 GMT Cache-Control: max-age=604800 Cache-Control: s-maxage=604800,max-age=604800 Age: 6425 X-Cache: HIT TCP_MEM_HIT dirn:0:1402323922 X-Swift-SaveTime: Wed, 27 Jul 2016 06:34:10 GMT X-Swift-CacheTime: 604800 Via: 440d210b[0,206-0,H] Length: 65707724 (63M) [video/x-msvideo] Saving to: 'DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610.1’ So Download Manager must be getting the info from the metadata at the start of the file. For example, I only downloaded the first 70KB of the file, and: ~/tmp$ file DARNA-ZAROORI-HAI-3\(Movies7.In\).avi\?md5=TU7ibYa85byjzJyJcH_LXQ\&expires=1458916610 DARNA-ZAROORI-HAI-3(Movies7.In).avi?md5=TU7ibYa85byjzJyJcH_LXQ&expires=1458916610: RIFF (little-endian) data, AVI, 640 x 360, ~30 fps, video: H.264 X.264 or H.264, audio: MPEG-1 Layer 3 (stereo, 22050 Hz) So the info is there at the start. I expect you'll want to use a library to parse it out. I'm not sure if Qt has such functionality built-in. Perhaps have a look through the Qt Multimedia docs. Cheers.
    • UNSOLVED QNetworkAccessManager FTP request without HELP
      General and Desktop • qnetworkaccessm ftp • • Rinin  

      2
      0
      Votes
      2
      Posts
      741
      Views

      Hi and welcome to devnet, Did you try to access the server ? What did you try ?
    • UNSOLVED Memory leak in QNetworkProxy (should i post on bugtracker?)
      General and Desktop • qnetworkaccessm memory leak qnetworkreply qnetworkrequest qnetworkpoxy • • Vlad_Savelyev  

      3
      0
      Votes
      3
      Posts
      1002
      Views

      sure i will reply with the project code
    • UNSOLVED Set custom socket on QNetworkAccessManager request
      General and Desktop • qtcpsocket qnetworkaccessm qnetwork socks4 winsock • • eventhorizon99  

      2
      0
      Votes
      2
      Posts
      1102
      Views

      Hi and welcome to devnet, Maybe QNetworkProxy might something. Hope it helps
    • SOLVED QNetworkReply, HTTP file download, and error headers on failure
      General and Desktop • qnetworkaccessm qnetworkreply • • Catherine Olsen  

      3
      0
      Votes
      3
      Posts
      734
      Views

      @Catherine-Olsen Maybe you could post your solution here so if others are facing similar problems they can find a way to go? ;)
    • SOLVED how to get Transfer rate when downloading file
      General and Desktop • qnetworkaccessm qnetworkreply transfer rate • • ARASHz4  

      4
      0
      Votes
      4
      Posts
      934
      Views

      @the_ I can't even math anymore. thanks for the correction
    • UNSOLVED HTTP response time with QNetworkAccessManager is more when compared to Dlib and Libcurl
      General and Desktop • qnetworkaccessm qnetworkreply qnetworkrequest qurl • • ksranjith786  

      10
      0
      Votes
      10
      Posts
      3482
      Views

      @ksranjith786 said: Could you please provide guidelines or code snippet to use QNetworkAccessManager using multi threaded env. No, I can't, sorry. Not that I don't want to, but I don't know of any way you can control the number of threads QNetworkAccessManager uses internally (I think it's hardcoded). If I were to do multithreading with NAM I'd do it like you - thread the reply's processing. Unfortunately this bears no weight on the HTTP response time. On a related note, I would always prefer to use TCP/IP directly, as it provides much more fine-grained control of what's happening (including threading). The downside of that approach however, is that it'd require implementing the HTTP protocol by hand. Perhaps, as @p3c0 suggested, you could try to ask the question on the mailing list were you might get responses from the actual developers of the module. Kind regards.
    • UNSOLVED QNetworkAccessManager with PHP and MYSQL
      Mobile and Embedded • mysql qnetworkaccessm php • • werter  

      12
      0
      Votes
      12
      Posts
      9814
      Views

      Thank you. I take a look on it.
    • SOLVED QNetworkAccessManager is not sending data part of POST request
      General and Desktop • qnetworkaccessm http-post • • CupaMurdosan  

      4
      0
      Votes
      4
      Posts
      2491
      Views

      Thank you guys for your replies. Problem is solved - I was wrong with wireshark - data were sent in another packet [TCP segment of a reassembled PDU].
    • http post data encoding
      General and Desktop • qnetworkaccessm qurl post • • 4j1th  

      4
      0
      Votes
      4
      Posts
      2877
      Views

      @4j1th said: Hi @Paul-Colby , by using the first method how can I access the file (in server), is it works as a file uploading method ? It depends on your server. What language is your server written with? (Assuming you're POSTing to your own server, and not some third-party API). For example, the server was running PHP, you could do something like: $data = json_decode(file_get_contents('php://input'), true); // save $data to a file somewhere. In that case, you wouldn't need to use WWW form encoding.
    • QNetworkAccessManager - first GET very slow
      General and Desktop • network qnetworkaccessm http qnetworkrequest get • • Aerius  

      15
      0
      Votes
      15
      Posts
      7722
      Views

      @djee In My Way connectToHost To Http Server Not Working, So I Call QSslConfiguration::defaultConfiguration(); Instead.
    • SOLVED How to load a .p12 key into the QSslKey object?
      Qt WebKit • qnetworkaccessm qsslconfigurati qsslkey • • GoneWithTheFood  

      3
      0
      Votes
      3
      Posts
      2260
      Views

      @luca yes you are right. :) Just now I've tried to export the private key from the .p12 file with the openssl API. This key could be constructed into QSslKey object now. Thanks a lot. But to configure in such a way is a little bit too complicated. Is there any class or method I can use, so that I can directly import the .p12 file into the QSslConfiguration object?
    • Put request in Qt using QNetworkAccessManager
      Mobile and Embedded • qnetworkaccessm put • • nimadid  

      6
      0
      Votes
      6
      Posts
      4605
      Views

      You should also connect the error signal to see if you it tells you something useful.
    • QNetworkAccessManager finished signal error
      General and Desktop • qnetworkaccessm signals emit • • 4j1th  

      16
      0
      Votes
      16
      Posts
      6118
      Views

      Since it's a QObject you can use the parent/child paradigm to let Qt handle the deletion for you.
    • UNSOLVED QNetworkAccessManager and POST return
      General and Desktop • qnetworkaccessm post return • • Helson  

      11
      0
      Votes
      11
      Posts
      15329
      Views

      You are welcome! Have a nice day :)
    • SOLVED QNetworkAccessManager Download Image
      General and Desktop • qpixmap qnetworkaccessm • • elveatles  

      5
      0
      Votes
      5
      Posts
      1833
      Views

      Printing out thumbnailData.data(), I get: 302 Found The resource was found at https://... So I realize my problem now. The thumbnail url is redirecting me to another url which is what I actually want to use to download for the QPixmap. Thanks for your help everyone.
    • QtWebEngine porting : custom file storage or html archive file
      General and Desktop • qtwebengine qnetworkaccessm qtwebkit qrc zip • • QbProg  

      1
      0
      Votes
      1
      Posts
      703
      Views

      No one has replied

    • QNetworkAccessManager throw "QWaitCondition" warning.
      General and Desktop • qnetworkaccessm • • kartlee144  

      2
      0
      Votes
      2
      Posts
      1238
      Views

      I found this link discussing about the trace seen in Windows https://bugreports.qt.io/browse/QTBUG-7691 Not sure if this is still related to mine.
    • downloadProgress bytesTotal -1
      General and Desktop • qnetworkaccessm qnetworkreply • • Franckynos  

      5
      0
      Votes
      5
      Posts
      1648
      Views

      @Franckynos said: But there isn't way to have a real progression ? It depends on whether or not the server sends correct Content-Length field in the header. It's not like Qt can magically guess the value if the server didn't send it. It's a bullshit to remove QFtp class. Huh. What does that out of context comment have to do with the issue? I can't have size of file with some request ? See above.
    • Getting two QNetworkReply after request
      General and Desktop • qnetworkaccessm qnetworkreply • • David.G  

      1
      0
      Votes
      1
      Posts
      542
      Views

      No one has replied

    • [SOLVED]Exe file crashes
      General and Desktop • qtcpsocket qnetworkaccessm • • andrewkiko  

      4
      0
      Votes
      4
      Posts
      2484
      Views

      You're welcome ! Since you have it running now, please update the thread title prepending [solved] so other forum users may know a solution has been found :) Also, consider up-voting answer(s) that helped you, it will make them easier to find for other users :)
    • Troubled by memory leak problem in QNetworkAccessManager !!!
      General and Desktop • qnetworkaccessm memory leak qnetwork • • sczhengyabin  

      3
      0
      Votes
      3
      Posts
      2228
      Views

      It's a mistake when I copy the code from other place. Here are the exact code below that I just write for this network test. The bigger the count of request sent in a loop, the more consumed virtual memory of this program. And after finished all of these http requests, the Virtual Memory of this program did not reduce. However, when I add a qWait(1) between every request, the memory will not goes up when the number of sent requests grows. But the memory still doesn't go down when I delete everything I used to access network. It seems when concurrently create and send a large amount of http requests through QNetworkAccessManager, the memory leakage will happen. //Header** #ifndef NETWORK_H #define NETWORK_H #include <QObject> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> #include <QUrl> #include <QTest> class NetWork : public QObject { Q_OBJECT private: explicit NetWork(QObject *parent = 0); public: static NetWork *Instance(); void Post(const QUrl &url, const QByteArray content); void Get(const QUrl &url); void Clean(); void Print(); QNetworkAccessManager *Manager(); signals: public slots: void SlotPostFinished(); void SlotCountDestroyed(); private: static NetWork *_network; QNetworkAccessManager *_manager; public: qint32 _countOk, _countError, _countSent, _countDestroyed; }; class UnitTest_Network : public QObject{ Q_OBJECT public: explicit UnitTest_Network(QObject *parent = 0); private slots: void test10ps(); void test10ps_data(); }; #endif // NETWORK_H //CPP #include "network.h" NetWork::NetWork(QObject *parent) : QObject(parent) { _manager = new QNetworkAccessManager(this); } NetWork *NetWork::_network = NULL; NetWork *NetWork::Instance() { if(_network == NULL){ _network = new NetWork(); } return _network; } void NetWork::Post(const QUrl &url, const QByteArray content) { QNetworkRequest request(url); request.setRawHeader("Content-Type", "application/json"); QNetworkReply *reply = _manager->post(request, content); connect(reply, SIGNAL(finished()), this, SLOT(SlotPostFinished())); connect(reply, SIGNAL(destroyed()), this, SLOT(SlotCountDestroyed())); } void NetWork::Get(const QUrl &url) { QNetworkRequest request(url); request.setRawHeader("Content-Type", "application/json"); QNetworkReply *reply = _manager->get(request); connect(reply, SIGNAL(finished()), this, SLOT(SlotPostFinished()), Qt::DirectConnection); connect(reply, SIGNAL(destroyed()), this, SLOT(SlotCountDestroyed())); } void NetWork::Clean() { _countOk = 0; _countError = 0; _countSent = 0; _countDestroyed = 0; } void NetWork::Print() { qDebug("10 ps:\t Sent = %d, Ok = %d, Error = %d, Destroyed = %d", _countSent, _countOk, _countError, _countDestroyed); qApp->processEvents(); } QNetworkAccessManager *NetWork::Manager() { return _manager; } void NetWork::SlotPostFinished() { QNetworkReply reply = (QNetworkReply)sender(); qint32 statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if(!reply->error()){ _countOk++; } else{ _countError++; } reply->readAll(); reply->abort(); reply->close(); reply->deleteLater(); } void NetWork::SlotCountDestroyed() { _countDestroyed++; } void UnitTest_Network::test10ps() { } void UnitTest_Network::test10ps_data() { QTest::addColumn<qint32>("hehe"); NetWork::Instance()->Clean(); qDebug("Test 10 ps ..."); qint32 count = 500; qDebug("Starting ..."); QTest::qWait(1000); for(int j=0; j<10; j++){ for(int i=0; i<count; i++){ NetWork::Instance()->Post(QString("http://192.168.0.90/rest/Logs/"), QByteArray("{\"reserve\" : \"\", \"logTime\" : 1410865245827, \"machineId\" : \"0023\", \"operationCode\" : \"x\", \"deviceNum\" : \"b\", \"deviceAttribute\" : \"5\",\"parameter\" :\"0624\", \"checksum\" : -111, \"serialNum\" : \"92bb\"}")); NetWork::Instance()->_countSent++; // QTest::qWait(1); // qApp->processEvents(); } qDebug("LOOP No.%d", j); } while(1){ if(NetWork::Instance()->_countSent == NetWork::Instance()->_countError + NetWork::Instance()->_countOk) break; NetWork::Instance()->Print(); QTest::qWait(5000); } qDebug("delete manager ..."); QTest::qWait(5000); NetWork::Instance()->Manager()->deleteLater(); qDebug("wait ..."); QTest::qWait(5000); qDebug("delete network ..."); NetWork::Instance()->deleteLater(); QTest::qWait(5000); qDebug("End ..."); QTest::qWait(10000); } UnitTest_Network::UnitTest_Network(QObject *parent) { } QTEST_MAIN(UnitTest_Network)
    • Multiples Connections in QML
      QML and Qt Quick • qml c++ qtquick qnetworkaccessm json qnetworkreply connections • • Antonio Ortiz  

      2
      0
      Votes
      2
      Posts
      2209
      Views

      Not quite understand your question.. Generally speaking, Javascript application use a Promise object for deferred and asynchronous operation. For example , do something when two or more asynchronous operations completed (in any order). Qt do not bundle any Promise implementation by default. You could get a one from my github repo: benlau/quickpromise Example Promise { resolveWhen: Q.all([endpoint1. onReplyStatusChanged,endpoint2. onReplyStatusChanged]); onFulfilled: { // It will be triggered only if both of the endpoint emitted the signal controller.setData1(); controller.setData2(); } }