PDA

View Full Version : restrict QLabel Internet assess



Kirsan
22nd April 2018, 01:04
Hi. Any one know how to prevent QLabel dig into internet when loading html? We load small compatible with QLabel html files. But if user by mistake try to load file saved from internet, it take very long time, and program begin lagging. But when internet assess is disabled - any file loading quickly with no lag.
Is it possible to restrict QLabel loading external links in html?

Santosh Reddy
23rd April 2018, 08:06
You could connect to signal linkActivated(), and do the internet available check and do required stuff.

Kirsan
23rd April 2018, 09:40
You could connect to signal linkActivated(), and do the internet available check and do required stuff.

Hi, thanks for your answer, but how "link user interaction signal" related to my question? I need to prevent internal QLabel internet access, while it loading initial html file - before user see any text on screen.

ChrisW67
25th April 2018, 01:45
You can (should always) sanitise the user input before giving it to QLabel. The simplest approach might be to start with: If the text provided contains "http://" or "https://" then reject it. If you need to load local resources from an intranet then: If the text provided contains "http://site/" or "https://site/" where site is not one of yours then reject it.

Kirsan
25th April 2018, 09:31
Thank you, I came to about the same decision. But sadly, "http://" or "https://" can occur in comment sections, for example:

<!--HTML generated by ..., http://...--> So it's not the simple regexp search...

ChrisW67
25th April 2018, 10:34
In <a> or <img> elements the URLs will be href="..." or src="http://..." so look for the attribute name as well would help.