How can I send requests over two network interfaces using QtWebkit? The test code seems to use the same interface. The question is:
QNetworkSession
?:Sample code:
// main.cpp
QList<QNetworkSession*> sessions;
QList<QNetworkConfiguration> configs = configManager.allConfigurations(QNetworkConfiguration::Active);
foreach (const QNetworkConfiguration& config, configs) {
sessions << new QNetworkSession(config);
qDebug() << "Preparing network session on " << config.name();
}
foreach (QNetworkSession* session, sessions) {
QWebPage* page = new QWebPage();
PageViewer* viewer = new PageViewer(0);
QObject::connect(page,SIGNAL(loadFinished(bool)),viewer,SLOT(showResults(bool)));
viewer->setPage(page);
page->setNetworkAccessManager(&accessManager);
session->open();
qDebug() << "Internal IP reported by the interface is:\t\t"
<< session->interface().addressEntries().at(0).ip().toString();
session->waitForOpened();
page->mainFrame()->load(QUrl("http://wtfismyip.com/text"));
session->close();
}
// page-viewer.cpp
void PageViewer::showResults(bool results)
{
qDebug() << "External IP reported by `http://wtfismyip.com/text' is:\t" <<
this->page->mainFrame()->toPlainText().trimmed();
}
QNetworkSession defines if an interface is available, but it has no effect on the routing of packets.
QtWebKit passes all its network connection through QNetworkAccessManager::get, and ultimately through QTcp/SslSocket, but I don't think that it uses QAbstractSocket::bind which could be used to define which interface should be used.
So sadly I'd say that this can't be controlled through the API, this is something that might be easier to tweak at the OS routing level unless you're willing to modify QNetworkAccessManager's code.