문제

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!

도움이 되었습니까?

해결책 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.

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top