Thursday, July 2, 2009

QtWebkit over the proxy

I wrote some posts about QtWebkit. But these may fail if your program runs behind the proxy. Then I rewrite programs in phosphorescence: QtWebkit HTML5 practice like below. Additional codes are blue characters.

Qt program
#include <QApplication>
#include <QUrl>
#include <QWebView>
#include <QNetworkProxy>

int main(int argc, char *argv[]){
QApplication a(argc, argv);
QNetworkProxy proxy(QNetworkProxy::HttpProxy, "proxy.host", proxy.port);
QNetworkProxy::setApplicationProxy(proxy);

QUrl url("http://htmlfive.appspot.com/static/draw.html");
QWebView* webView = new QWebView();
webView->load(url);
webView->show();
return a.exec();
}

QtRuby program
require 'Qt4'
require 'qtwebkit'

Qt::Application.new(ARGV) do
proxy = Qt::NetworkProxy.new(Qt::NetworkProxy::HttpProxy, "proxy.host", proxy.port)
Qt::NetworkProxy.application_proxy = proxy

Qt::WebView.new do
self.load Qt::Url.new('http://htmlfive.appspot.com/static/gifter.html')
show
end
exec
end


proxy.host and proxy.port should replace ones of your proxy environment.

No comments:

Post a Comment