qtnetwork

QNetworkAccessManager upload to local FTP server

女生的网名这么多〃 提交于 2019-12-22 12:23:58
问题 I can download from the server but I can't upload to it. It uploads the file but it's an empty file. This is basically what I'm doing: QString filename="Data.txt"; QFile file( filename ); file.open(QIODevice::ReadWrite); file.write("HELLO") ; QUrl urlup("ftp://127.0.0.1/file.txt"); urlup.setPassword("123"); urlup.setUserName("user"); urlup.setPort(21); QNetworkAccessManager *nam = new QNetworkAccessManager; QNetworkRequest requp(urlup); nam->put(requp,&file); file.close(); but it's not

Should I connect to QNetworkReply::error() as well?

一个人想着一个人 提交于 2019-12-22 11:28:02
问题 I have created a POST request and I connect to the finished() signal: QNetworkReply *reply = manager->post(request, postData.encodedQuery()); connect(reply, SIGNAL(finished()), this, SLOT(accept())); I want to be notified when the POST request has finished, regardless of whether it failed or succeeded. I have noticed in the documentation that there is also a QNetworkReply::error() signal, do I need to connect to it, too, or will finished() be called in all cases? 回答1: Qt documentation states:

Qt synchronous QNetworkAccessManager get

狂风中的少年 提交于 2019-12-21 17:11:02
问题 What's the proper way to do a synchronous QNetworkAccessManager::get ? The qt wiki offers an approach, but states "it is not recommended to use this in real applications." The mailinglist offers a similar solution to the wiki. 回答1: Yum may use something like this: QEventLoop loop; connect(_netReply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); 回答2: The simple solution mentioned in the wiki and in the answer from yttrium is quite fragile since it doesn't handle all possible failure

QHttpMultiPart: post files to PHP script

风流意气都作罢 提交于 2019-12-21 02:41:42
问题 I am working in Qt 5 and struggling with a multipart upload. My script is as close to the docs as possible: QUrl testUrl("http://localhost/upload/test.php"); QNetworkRequest request(testUrl); QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QString preview_path = "C:/preview.jpg"; QHttpPart previewPathPart; previewPathPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"preview_path\"")); previewPathPart.setBody(preview_path

Downloading a file with Qt?

一世执手 提交于 2019-12-20 05:13:16
问题 I am trying to figure out a way for my Qt browser app can download a word document from our web app. The web app is written in ExtJS, when (in a browser such as Chrome) a user clicks the "Download report" button a javascript event listener detects that click and opens a 0px0px iframe and the file downloads. I'm not sure how to replicate this browser feature in Qt? When I click on the link I get a network reply of "Operation canceled" 5 ? What class/method would be best to retrieve these files

How to send data back from PHP after a HTTP Post in Qt?

北城以北 提交于 2019-12-12 02:02:32
问题 I'm using this code to make a simple HTTP Post ( a login ) QNetworkAccessManager *nwam = new QNetworkAccessManager; QNetworkRequest request(QUrl("http://localhost/laptop/trylogin.php")); QByteArray data; QUrl params; QString userString(user); QString passString(pass); params.addQueryItem("user", userString ); params.addQueryItem("pass", passString ); data.append(params.toString()); data.remove(0,1); QNetworkReply *reply = nwam->post(request,data); If the logging succeedes or not, how do i

QTcpSocket memory leaking

别说谁变了你拦得住时间么 提交于 2019-12-11 11:23:06
问题 I have a client-server application setup using QTcpServer and QTcpSockets and seem to have some huge memory leaks. I'm wondering if the problem is in my use of Qt's sockets because I have just set up a simple test application and after sending 250,000,000 messages in a loop my client rises up to 75 meg. It seems that if I have several million messages, I see 300+ MB of memory used in my client. This doesn't seem right to me, as I keep sending messages the memory just keeps on rising! So

Qt 5.2.0 ftp and QNetworkAccessManager

依然范特西╮ 提交于 2019-12-11 08:19:23
问题 I need to be able to create directories on my ftp server. I know that there's no QFtp in the 5.2.1 qt, so how do I mkdir with QNetworkAccessManager ? 回答1: QNetworkAccessManager doesn't support that 回答2: Although it is recommended to use QNetworkAccessManager as much as possible, you always fall back to the QtFtp add-on as follows: QT += ftp Then, you will be able to use the mkdir method of the QFtp class. 来源: https://stackoverflow.com/questions/22250898/qt-5-2-0-ftp-and-qnetworkaccessmanager

How to save the http session in qt application

怎甘沉沦 提交于 2019-12-11 03:39:01
问题 Now I have a web server written with php. And there some php script files for database accessing. I'm writing a Qt app to send get/post request to the remote php scripts. However, it's not convenient to verify user identity for each request. So, I want to use session control on the web server. But I don't know how to do in Qt application. 回答1: As Orangepill and PLB said, the solution is Passing cookies to the request url , you may refer to QNetworkAccessManager::setCookieJar . Steps

QtNetwork SSL Handshake error on https://service.oneaccount.com/onlineV2_B/OSV2?event=login&pt=3

删除回忆录丶 提交于 2019-12-11 02:09:23
问题 When I use my QT application to download this page: https://service.oneaccount.com/onlineV2_B/OSV2?event=login&pt=3 with QNetworkAccessManager->get(url), I got a network error (QNetworkReply::NetworkError) in the reply object. The error string is SSL handshake failed. However, the sslErrors signal is not fired so I don't even get the chance to ignore this error. I got the same problem on Mac and Windows version. If I do the same thing with QT 4.74. It works fine. 回答1: Using QSslSocket: