Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is there any way to make webkit use specific network interface



  • Hi all,
    I'm trying QT5 on a linux box which has multple network interfaces. I would like to use webkit to show the wifi web portal and therefore the traffic of webkit should only go through wlan instead of any other interfaces. I came up with two ideas:
    1 use iptables to redirect all packets with port 80 to wlan
    2 make wlan the default gateway
    But both of them may affect existing connections. I'm wondering is there a better way to bind webkit's sockets to the specified network interface?
    Thanks



  • Just figured out that the correct way is using QNetworkAccessManager:

    QNetworkConfigurationManager manager;
    QList<QNetworkConfiguration> listCfg = manager.allConfigurations();
    foreach(const QNetworkConfiguration& now, listCfg){
    	if (now.name() == strIf) {
    		ui->frameWeb->page()->networkAccessManager()->setConfiguration(now);
    		break;
    	}
    }

Log in to reply