Search Results

Search found 19 results on 1 pages for 'qnetworkaccessmanager'.

Page 1/1 | 1 

  • Uploading a file using post() method of QNetworkAccessManager

    - by user304361
    I'm having some trouble with a Qt application; specifically with the QNetworkAccessManager class. I'm attempting to perform a simple HTTP upload of a binary file using the post() method of the QNetworkAccessManager. The documentation states that I can give a pointer to a QIODevice to post(), and that the class will transmit the data found in the QIODevice. This suggests to me that I ought to be able to give post() a pointer to a QFile. For example: QFile compressedFile("temp"); compressedFile.open(QIODevice::ReadOnly); netManager.post(QNetworkRequest(QUrl("http://mywebsite.com/upload") ), &compressedFile); What seems to happen on the Windows system where I'm developing this is that my Qt application pushes the data from the QFile, but then doesn't complete the request; it seems to be sitting there waiting for more data to show up from the file. The post request isn't "closed" until I manually kill the application, at which point the whole file shows up at my server end. From some debugging and research, I think this is happening because the read() operation of QFile doesn't return -1 when you reach the end of the file. I think that QNetworkAccessManager is trying to read from the QIODevice until it gets a -1 from read(), at which point it assumes there is no more data and closes the request. If it keeps getting a return code of zero from read(), QNetworkAccessManager assumes that there might be more data coming, and so it keeps waiting for that hypothetical data. I've confirmed with some test code that the read() operation of QFile just returns zero after you've read to the end of the file. This seems to be incompatible with the way that the post() method of QNetworkAccessManager expects a QIODevice to behave. My questions are: Is this some sort of limitation with the way that QFile works under Windows? Is there some other way I should be using either QFile or QNetworkAccessManager to push a file via post()? Is this not going to work at all, and will I have to find some other way to upload my file? Any suggestions or hints would be appreciated. Thanks, Don

    Read the article

  • QNetworkAccessManager and QHttp doesn't sends anything

    - by serge
    Hi everyone, i wrote some app and trying with a help of QNetworkAccessManager send some data to server using POST request, however nothing happen at all. I tried to use QHttp and the same result. I have checked it with WireShark - none requests in the list from my program. I tried to send GET request and the same - none requests. I created project with Network libs, got example from help: manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requesReply(QNetworkReply*))); QNetworkRequest req; req.setUrl(QUrl("http://server.net/upload")); manager->get(req); Please help me to find what i'm missing. Thanks in advance

    Read the article

  • QNetworkAccessManager timeout.

    - by Umesha MS
    Hi, Presently I am working on an application which sends and receives file from remote server. To do network operation I am using QNetworkAccessManager. To upload a file I am using QNetworkAccessManager::put() and to download I am using QNetworkAccessManager::get() functions. While uploading a file I will initialize a timer with time out of 15 sec. if I upload a small file it will complete it within the time out period. But if I try to upload a file which is very large in size get time out. So how to decide time out for uploading of large file. Same in case of downloading of a large file. I get file in chunk by chunk in readyread() signal. Here also if I download a large file I get time out. So how to decide time out for uploading of large file.

    Read the article

  • Qt QNetworkAccessManager does not emit signals

    - by Emilio
    The function CheckSite() is called with an url like http://site.com, it initializes a QNetworkAccessManager object and connect() slots and signals. The manger-get() call seems work (it generates http traffic) but does not call the slot replyFinished() at the request end. What's wrong with this code? #include <QtCore> #include <QtNetwork> class ClientHandler : public QObject { Q_OBJECT QNetworkAccessManager *manager; private slots: void replyFinished(QNetworkReply *); public: void CheckSite(QString url); }; void ClientHandler::replyFinished(QNetworkReply *reply) { qDebug() << "DONE"; } void ClientHandler::CheckSite(QString url) { QUrl qrl(url); manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); manager->get(QNetworkRequest(qrl)); }

    Read the article

  • how can i make sure to get the server response correctly when i invoke the server with QNetworkReque

    - by noname
    I wrote the server site call in Qt, but i haven't get the server response for every server invoking. I have to use the server reply to continue the program flow. The request is correctly reached to server and server do reply.The server is also on my machine. Here is the code how i make the server site call; QNetworkAccessManager nam1 = new QNetworkAccessManager(this); qnetmg=nam1; QObject::connect(nam1, SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedGettingMarker(QNetworkReply*))); QString strurl="http://localhost:8080/ServerWeb"; QUrl url(strurl); QNetworkRequest preq(url); QNetworkReply* reply = nam1->get(preq); qreply=reply; Inside finisedGettingMarker slot, i have already eliminate for QNetworkReply-error case and i used one global variable for QNetworkAccessManager;"qnetmg" and one global variable for QNetworkReply;"qreply". And also i make qnetmg.disconnect(this,0); and qreply.abort(); inside that slot method. But the problem is i haven't got the response for every server invoking time. If anyone who know the way to solve it , please reply me. This situation happened only in Opera. Thanks in advance.

    Read the article

  • Qtestlib: QNetworkRequest not executed

    - by dzen
    I would like to test an asynchronous request to a webserver. For that purpose I'm creating a simple unittest to quickly try a few lines of code: void AsynchronousCall::testGet() { QNetworkAccessManager *nam = new QNetworkAccessManager(this); QUrl url("http://myownhttpserver.org"); QNetworkRequest req(url); this->connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(reqFinished(QNetworkReply *))); QNetworkReply *rep = nam->get(req); } void AsynchronousCall::reqFinished(QNetworkReply *rep) { qDebug() << rep->readAll(); qDebug() << "finshed"; } The problem is that reqFinished() is never reached. If I had a simple QEventLoop and and a loop.exec() just after the nam-get(req); the request is executed. Any hint ? Do I have to use a loop.exec() in my every unittests ?

    Read the article

  • Qt Jambi: Accessing the content of QNetworkReply

    - by Richard
    Hi All, I'm having trouble accessing the content of QNetworkReply objects. Content appears to be empty or zero. According to the docs (translating from c++ to java) I think I've got this set up correctly, but to no avail. Additionally an "Unknown error" is being reported. Any ideas much appreciated. Code: public class Test extends QObject { private QWebPage page; public Test() { page = new QWebPage(); QNetworkAccessManager nac = new QNetworkAccessManager(); nac.finished.connect(this, "requestFinished(QNetworkReply)"); page.setNetworkAccessManager(nac); page.loadProgress.connect(this, "loadProgress(int)"); page.loadFinished.connect(this, "loadFinished()"); } public void requestFinished(QNetworkReply reply) { reply.reset(); reply.open(OpenModeFlag.ReadOnly); reply.readyRead.connect(this, "ready()"); // never gets called System.out.println("bytes: " + reply.url().toString()); // writes out asset uri no problem System.out.println("bytes: " + reply.bytesToWrite()); // 0 System.out.println("At end: " + reply.atEnd()); // true System.out.println("Error: " + reply.errorString()); // "Unknown error" } public void loadProgress(int progress) { System.out.println("Loaded " + progress + "%"); } public void loadFinished() { System.out.println("Done"); } public void ready() { System.out.println("Ready"); } public void open(String url) { page.mainFrame().load(new QUrl(url)); } public static void main(String[] args) { QApplication.initialize(new String[] { }); Test t = new Test(); t.open("http://news.bbc.co.uk"); QApplication.exec(); } }

    Read the article

  • How can I use Qt to get html code of the redirected page??

    - by Claire Huang
    I'm trying to use Qt to download the html code from the following url: http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nucleotide&cmd=search&term=AB100362 this url will re-direct to www.ncbi.nlm.nih.gov/nuccore/27884304 I try to do it by following way, but I cannot get anything. it works for some webpage such as www.google.com, but not for this NCBI page. is there any way to get this page?? QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data) { QNetworkAccessManager manager; QNetworkRequest request(url); QNetworkReply *reply = manager.get(request); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); if (reply->error() != QNetworkReply::NoError) { return reply->error(); } data = reply->readAll(); delete reply; return QNetworkReply::NoError; } void GetGi() { int pos; QString sGetFromURL = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"; QUrl url(sGetFromURL); url.addQueryItem("db", "nucleotide"); url.addQueryItem("cmd", "search"); url.addQueryItem("term", "AB100362"); QByteArray InfoNCBI; int errorCode = downloadURL(url, InfoNCBI); if (errorCode != 0 ) { QMessageBox::about(0,tr("Internet Error "), tr("Internet Error %1: Failed to connect to NCBI.\t\nPlease check your internect connection.").arg(errorCode)); return "ERROR"; } }

    Read the article

  • How to set QNetworkReply properties to get correct NCBI pages?

    - by Claire Huang
    I try to get this following url using the downloadURL function: http://www.ncbi.nlm.nih.gov/nuccore/27884304 But the data is not as what we can see through the browser. Now I know it's because that I need to give the correct information such as browser, how can I know what kind of information I need to set, and how can I set it? (By setHeader function??) In VC++, we can use CInternetSession and CHttpConnection Object to get the correct information without setting any other detail information, is there any similar way in Qt or other cross-platform C++ network lib?? (Yes, I need the the cross-platform property.) QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data) { QNetworkAccessManager manager; QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader ,"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)"); QNetworkReply *reply = manager.get(request); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); QVariant statusCodeV = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); QUrl redirectTo = statusCodeV.toUrl(); if (!redirectTo.isEmpty()) { if (redirectTo.host().isEmpty()) { const QByteArray newaddr = ("http://"+url.host()+redirectTo.encodedPath()).toAscii(); redirectTo.setEncodedUrl(newaddr); redirectTo.setHost(url.host()); } return (downloadURL(redirectTo, data)); } if (reply->error() != QNetworkReply::NoError) { return reply->error(); } data = reply->readAll(); delete reply; return QNetworkReply::NoError; }

    Read the article

  • How can I set QNetworkReply properties to get correct NCBI pages?

    - by Claire Huang
    I try to get this following url using the downloadURL function: http://www.ncbi.nlm.nih.gov/nuccore/27884304 But the data is not as what we can see through the browser. Now I know it's because that I need to give the correct information such as browser, how can I know what kind of information I need to set, and how can I set it? (By setHeader function??) In VC++, we can use CInternetSession and CHttpConnection Object to get the correct information without setting any other detail information, is there any similar way in Qt or other cross-platform C++ network lib?? (Yes, I need the the cross-platform property.) QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data) { QNetworkAccessManager manager; QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader ,"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)"); QNetworkReply *reply = manager.get(request); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); int direction; QVariant statusCodeV = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); QUrl redirectTo = statusCodeV.toUrl(); if (!redirectTo.isEmpty()) { if (redirectTo.host().isEmpty()) { const QByteArray newaddr = ("http://"+url.host()+redirectTo.encodedPath()).toAscii(); redirectTo.setEncodedUrl(newaddr); redirectTo.setHost(url.host()); } return (downloadURL(redirectTo, data)); } if (reply->error() != QNetworkReply::NoError) { return reply->error(); } data = reply->readAll(); delete reply; return QNetworkReply::NoError; }

    Read the article

  • How to inject local CSS and JavaScript from qrc:// into QWebView?

    - by speakman
    Trying to inject CSS and JS files reachable through Qt resources (qrc://) through JavaScript (using this technique) which itself is injected through a evalutateJavaScript() call fails fails miserably hitting this test in QNetworkAccessFileBackend. I can't figure how to make this work, really. I could subclass QNAFB but then I would need to subclass QNAM as well to make it instance my subclass instead of QNAFB?

    Read the article

  • waiting for a signal

    - by Umesha MS
    Hi, I am working on an application which uploads the content of the file to server. To upload the file to server I am using ‘QNetworkAccessManager’ class. Since it works as asynchronous way, I changed it to work as synchronous way by using QEventLoop. Class FileTransfer { Public : QNetworkAccessManager mNetworkManager; Void Upload(QNetworkRequest request, QIODevice *data) { responce = mNetworkManager.put(request, data); EventLoop.exec(); ReadResponce(responce); } Void Stop() { responce ->close(); } } In my sample application I have 2 windows. 1st to select the files and 2nd to show the progress. When user click on upload button in the first window, the 2nd window will be displayed and then I create the FileTransfer object and start uploading. While uploading the file if user closes the form then in the destructor of the window I call the stop of ‘FileTransfer’ after that I delete the ‘FileTransfer’ object. But here the Upload() function is not yet completed so it will crash. Please help me to: How to wait in 'stop()' function until the Upload() function is completed

    Read the article

  • Qt et la communication réseau, un tutoriel de rocsan

    Bonjour, Aujourd'hui, un tutoriel un peu plus ancien est disponible, il vous montre comment utiliser le réseau avec Qt. À sa sortie, les classes du QNetworkAccessManager n'étaient pas encore disponibles, il ne présente donc que QFtp et QHttp à cet effet, à titre historique ; cependant, là ne réside pas l'intérêt : vous avez toujours rêvé de coder une application client-serveur (comme, pour prendre pour exemple le projet le plus fou, un MMORPG) ? Eh bien, il est fort probable que vous deviez utiliser un protocole réseau dénommé TCP. Le voici présenté. Qt et la communication réseau...

    Read the article

  • Data loss when converting from QString to QByteArray

    - by SleepyCod
    I'm using QPlainTextEdit as an HTML editor, saving the data through an HTTP post with QNetworkAccessManager. I experience data loss when using HTML special characters such as & (ampersand) I'm building a POST request with a QByteArray (as mentioned in the docs). QByteArray postData; QMapIterator<QString, QString> i(params); while(i.hasNext()) { i.next(); postData .append(i.key().toUtf8()) .append("=") .append(i.value().toUtf8()) .append("&"); } postData.remove(postData.length()-1, 1); //Do request QNetworkRequest postRequest = QNetworkRequest(res); oManager.post(postRequest, postData);

    Read the article

  • Wait until a webpage finished loading to load the next one in a list

    - by envy
    Hi! I'm using PyQT webView to visit some webpages I have stored on a dictionary the code is something like this: def loadLink(self, url): manager = QNetworkAccessManager() request = QNetworkRequest(QUrl(url)) self.ui.webView.load(QUrl(visitar)) def readUnreadLinks(self): print "Links to read: " + str(len(self.unreadLinks)) for link in self.unreadLinks: print "link-> " + str(link) self.loadLink(link) the problem is it doesn't wait until finished loading the web page and starts loading the next one. I want to load a webpage, wait until it finished loading and then load the next one. Thanks, this is driving me crazy :)

    Read the article

  • Qt request never trigger the finished() signal

    - by user63898
    i have something realy strange i have this code : m_url.setUrl("www.cnn.com"); QNetworkRequest request; request.setRawHeader("User-Agent", USER_AGENT.toUtf8()); request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setRawHeader("Accept-Language", "en-us,en;q=0.5"); request.setRawHeader("Connection", "Keep-Alive"); request.setUrl(m_url); reply = qnam.get(request); //QNetworkAccessManager qnam member of the class; connect(reply, SIGNAL(finished()), this, SLOT(httpFinished())); the httpFinished() function that is under private slots: never triggered , why ?

    Read the article

  • How can I create a HTTP POST request with Qt 4.6.1?

    - by Tobias Langner
    How can I create a HTTP POST request with some URL encoded parameters using Qt 4.6.1? I figured out that I can create a QNetworkRequest, set all the parameters there and send it via QNetworkAccessManagers post method. But how can I add some URL-encoded parameters to the request? In the end I want to access the Eve API using Qt/C++. A Python example can be found here: http://www.eveonline.com/api/doc/example-python.asp I managed it using something like (still to be refactored and formed into something useful): QNetworkReply *requestApi(QNetworkAccessManager &nwam) { QNetworkRequest request(QUrl("http://api.eve-online.com/account/Characters.xml.aspx")); request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded"); QByteArray data; QUrl params; params.addQueryItem("userid","user"); params.addQueryItem("apiKey","key"); data.append(params.toString()); data.remove(0,1); QNetworkReply *reply = nwam.post(request,data); return reply; }

    Read the article

  • How can I use Qt to get html code of this NCBI page??

    - by user308503
    I'm trying to use Qt to download the html code from the following url: http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=nucleotide&cmd=search&term=AB100362 this url will re-direct to www.ncbi.nlm.nih.gov/nuccore/27884304 I try to do it by following way, but I cannot get anything. it works for some webpage such as www.google.com, but not for this NCBI page. is there any way to get this page?? QNetworkReply::NetworkError downloadURL(const QUrl &url, QByteArray &data) { QNetworkAccessManager manager; QNetworkRequest request(url); QNetworkReply *reply = manager.get(request); QEventLoop loop; QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); if (reply->error() != QNetworkReply::NoError) { return reply->error(); } data = reply->readAll(); delete reply; return QNetworkReply::NoError; } void GetGi() { int pos; QString sGetFromURL = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"; QUrl url(sGetFromURL); url.addQueryItem("db", "nucleotide"); url.addQueryItem("cmd", "search"); url.addQueryItem("term", "AB100362"); QByteArray InfoNCBI; int errorCode = downloadURL(url, InfoNCBI); if (errorCode != 0 ) { QMessageBox::about(0,tr("Internet Error "), tr("Internet Error %1: Failed to connect to NCBI.\t\nPlease check your internect connection.").arg(errorCode)); return "ERROR"; } }

    Read the article

1