Domanda

I am using Qt 4.7 for my current project. I have a QWebView object in a Dialog that I need to display a webpage that requires postdata (it is the result of a search). I have the following so far:

QNetworkAccessManager *nam;
ui->webView->page()->setNetworkAccessManager(nam);
QUrl url;
url.setHost("http://myhost.com");
url.setPath("/mypath.php");
QString postdata("value1=x&value2=y");

QNetworkRequest request(url);
ui->webView->load(request, QNetworkAccessManager::PostOperation, postdata.toStdStdring().c_str());

I tried to follow the docs as closely as possible, but they were very lacking in descriptions of this function and I had trouble finding much else online about it. When I run this in the browser using the same host and path, and the same data which I determined from tampering the request, I get the correct page. However, when I run it in the app, the webView is blank. Does anyone know what I may be doing wrong? I feel like it might be something simple, but like I said I had a hard time finding much that was helpful. Thanks!

È stato utile?

Soluzione 3

So, I was able to get this to work by taking the url.set*() lines and replacing them with url.setUrl(host + path). Honestly I'm not sure why that fixed it, since I sort of thought that does the same thing as the other two functions did before, but it does seem to work now.

Altri suggerimenti

Are you just trying to load www.myhost.com/mypath.php in QWebView?

Just use

QUrl url("http://myhost.com/mypath.php");
ui->webView->load(url);

It appears that you are not using the variable postdata and it's type should be QByteArray, like this:

QUrl url;
url.setHost("http://myhost.com");
url.setPath("/mypath.php");

QByteArray postdata;
postdata.append("value1=x");
postdata.append("&value2=y");

ui->webView->load(QNetworkRequest(url), QNetworkAccessManager::PostOperation, postdata);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top