Last active
October 5, 2019 06:30
-
-
Save obito02/141170dc8feaef53510464f627ff2987 to your computer and use it in GitHub Desktop.
Simple codigo usar QWebEngine con Proxy en Golang QT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/therecipe/qt/core" | |
"github.com/therecipe/qt/webengine" | |
"github.com/therecipe/qt/widgets" | |
"github.com/therecipe/qt/network" | |
"os" | |
) | |
//USER WEBENGINE CON PROXY EN GOLANG CON LA BIBLIOTECA QT. | |
func main() { | |
app := widgets.NewQApplication(len(os.Args),os.Args) | |
webengine.QtWebEngine_Initialize() | |
//En caso de no usar proxy eliminar | |
proxy := network.NewQNetworkProxy() | |
proxy.SetType(network.QNetworkProxy__Socks5Proxy) | |
proxy.SetHostName("127.0.0.1") | |
proxy.SetPort(1080) | |
network.QNetworkProxy_SetApplicationProxy(proxy) | |
//Este fragmento de codigo | |
webMotor := webengine.NewQWebEngineView(nil) | |
url := core.NewQUrl3("http://www.google.com",core.QUrl__TolerantMode) | |
perfile := webMotor.Page().Profile() | |
perfile.ClearAllVisitedLinks() | |
qq := webengine.NewQQuickWebEngineProfileFromPointer(perfile.Pointer()) | |
clearQQ(qq) | |
webMotor.Load(url) | |
webMotor.Show() | |
app.Exec() | |
clearQQ(qq) | |
} | |
func clearQQ(qq *webengine.QQuickWebEngineProfile) { | |
qq.ClearHttpCache() | |
qq.CookieStore().DeleteAllCookies() | |
qq.CookieStore().DeleteSessionCookies() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Debera instalar QT para golang, gracias a therecipe. | |
Seguir los pasos de instalación https://github.com/therecipe/qt | |
En este pequeño gist les muestro como usar basicamnete el QwebEngine que no hay ejemplos para el uso en golang. | |
y tambien como enlazar en apis que no existan dentro de los modulos en este caso .ClearAllVisitedLinks(), este metodo no esta | |
por defecto en el modulo webengine asi que tuve que agregarlo. | |
Nota. si no necesitas un ejemplo de como enlazar otras funciones que esten por defecto solo usa main.go, los demas archivos son para enlazar | |
la funcion no existente por defecto. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Tambien esto para que pueda ser llamado desde Go | |
void QWebEngineProfile_clearAllVisitedLinks(void* ptr) | |
{ | |
static_cast<QWebEngineProfile*>(ptr)->clearAllVisitedLinks(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//y por ultimo editamos sete archivo agregando al siguiente funcion, con eso ya podremos llamar a este metodo que por defecto | |
//no esta disponible. | |
func (ptr * QWebEngineProfile) ClearAllVisitedLinks() { | |
if ptr.Pointer() != nil { | |
C.QWebEngineProfile_clearAllVisitedLinks(ptr.Pointer()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Agregar esta linea a webengine.h que se encuentra en su $GOPATH/github.com/therecipe/qt/webengine/webengine.h | |
void QWebEngineProfile_clearAllVisitedLinks(void* ptr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment