Unsolved QTextBrowser::setSource() with non existent Url
-
If I call
QTextBrowser::setSource("file:non-existent-file.html")
I see the output window warns me:
QTextBrowser: No document for file:non-existent-file.html
but there is no return result or other means to know this has happened. I wish to detect it, how should I do so?
Should I rely on calling
QTextBrowser::sourceType() == QTextDocument::UnknownResource
after trying to set it? [EDIT Oh dear, I can't, for whatever reason does not exist in PySide2 for Qt 5.12.2'PySide2.QtWidgets.QTextBrowser' object has no attribute 'sourceType'
.]There is no simple/independent call to
QUrl("file:non-existent-file.html").doesThisExist()
[please note,.isValid()
only tests for Url format validity], and I really don't fell like doing someQNetwork...
stuff for this, deal with local files vs remote resources, etc. -
@JonB
QFile has a static member to check for a file existencehttps://doc.qt.io/qt-5/qfile.html#exists
works fore local, network and qrc files
Is that what you're looking for?
Edit:
just noticed you're looking for a network/html validation 🤔 That I don't know (Except QNetwork stuff) -
@J-Hilk
I thinkQTextBrowser::source()
looks in a variety of places (e.g.QTextBrowser::searchPaths()
), beyond whereQFile
looks. I wanted to know ifsetSource()
failed, regardless of local/network location, URL format, permissions, bad file type/HTML can't be loaded, whatever which would make source not load successfully....I guess I will have to treat special case of local file and just test for existence where I expect it to be, it will have to do me for now. Unless anyone can suggest better....