Important: Please read the Qt Code of Conduct -

QWebkit: downloading a page using a specific network interface

  • Hi Everybody,

    I have a PC with two network interfaces; eth0 and eth1
    eth1 has no IP address but it is bound to a ppp connection

    eth0 Link encap:Ethernet HWaddr 00:26:18:f1:91:d1
    inet addr: Bcast: Mask:

    ppp0 Link encap:Point-to-Point Protocol
    inet addr: P-t-P: Mask:

    I'd like is to be able to use Qt webkit to download pages using the ppp0 and not the eth0 interface.

    What I did at code level using Qt is the following:

    • Retrieve the list of available network configurations
    • Select the network configuration associated with the ppp0 iface
    • create a QNetworkAccessManager
    • set the configuration of the QNetworkAccessManager
    • create a QWebPage
    • set the network access manager of the webpage to the above one
    • load the webpage

    Unfortunately it seems that the data always exit via the eth0 iface (I monitored both ifaces with wireshark/tcpdump) The problem is not related to the routing configuration of the PC, I configured the system so that I can send packets out via the ppp0 iface.

    ie. ping -c 3 -I is correctly routed out via the ppp0 iface

    Here's a snapshot of my code:

    QNetworkConfigurationManager* m_netConfigMngPtr;
    QNetworkAccessManager* m_netAccessMngPtr;

    m_netConfigMngPtr = new QNetworkConfigurationManager();
    qDebug() << "network config manager capabilities" << m_netConfigMngPtr->capabilities();

    QList<QNetworkConfiguration> netConfigList = m_netConfigMngPtr->allConfigurations();

    QString ifaceId;
    qDebug() << Q_FUNC_INFO << "Available Networck configurations:" << netConfigList.size();
    foreach( QNetworkConfiguration c, netConfigList)
    qDebug() << Q_FUNC_INFO << "network configuration:" << c.identifier() << << c.state() << c.isValid();
    if ( == "ppp0")
    ifaceId = c.identifier();

    QNetworkConfiguration netConf = m_netConfigMngPtr->configurationFromIdentifier(ifaceId);
    qDebug() << "Net config for " << ifaceId << "(" << << ")" << "is valid: " << netConf.isValid();

    m_netAccessMngPtr = new QNetworkAccessManager;
    m_netAccessMngPtr->setConfiguration( netConf );

    QWebPage* m_theWebPagePtr = new QWebPage;
    m_theWebPagePtr->currentFrame()->load( QUrl("") );


    I'm using Qt 4.8.1 on Linux 64bit
    Any hint or suggestion on what I'm doing wrong?

Log in to reply