Iman
Iman

Reputation: 525

QtWebkit custom dns setting without system settings

I want to change my dns for every one of my request for some reasons! I work with Qt 5.3 and QtWebkit! I do search but i can not find anything that can help me!
Actually QDnsLookup can't force QtWebkit to set its load() function to use specific look up and it use the system Dns setting at the end!
Any idea?!

Upvotes: 0

Views: 255

Answers (1)

Xplatforms
Xplatforms

Reputation: 2232

Create you own QNAM subclass and QWebPage subclass. Implement you DNS resolver there. Then set it for each QWebPage you create. This way you will get full network control of what happens in WebKit. To be sure all WebPages will get your QNAM, subclass QWebView too and set your QWebPage subclass as page in constructor. Also overload createWindow function so all new QWebView pages(like popups) will be created as your QWebView subclass.

YourWebView::YourWebView(QWidget *parent):QWebView(parent)
{
    this->setPage(new YourWebPageSubclass());
    ...

QWebView * YourWebView::createWindow(QWebPage::WebWindowType type)
{
    YourWebView * view = Q_NULLPTR;    
    switch(type)
    {
    case QWebPage::WebBrowserWindow:
        view = new YourWebView(0);
        break;

    case QWebPage::WebModalDialog:
        view = new YourWebView(0);
        view->setWindowModality(Qt::ApplicationModal);
        break;
    }
    return view;
}

YourWebPageSubclass::YourWebPageSubclass(QObject *parent):QWebPage(parent)
{
    this->setNetworkAccessManager(new YourQNAM(this));
    ...

Upvotes: 1

Related Questions