I'm using QWebEngine with Qt5.9.1.
I want to inject webchannel and user script into some web page to communicate with my c++ code.
But there's always some alerting:
"[63092:96096:1015/025540.965:INFO:CONSOLE(438)] "Refused to connect to 'ws://127.0.0.1:12343/' because it violates the following Content Security Policy directive".
And user script cann't execute, too.
I have tried to disable Content Security Policy by:
page->settings()->setAttribute(QWebEngineSettings::XSSAuditingEnabled, false);
But this didn't work.
How should I disable CSP in qt webengine?
I found a solution:
I changed the address from ws://127.0.0.1:12343/
to ws://localhost:12343/
. The web channel can connect successfully.
I don't know the reason, but it works.