Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextBrowser::setSource() with non existent Url
Forum Updated to NodeBB v4.3 + New Features

QTextBrowser::setSource() with non existent Url

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 472 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    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 some QNetwork... stuff for this, deal with local files vs remote resources, etc.

    J.HilkJ 1 Reply Last reply
    0
    • JonBJ JonB

      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 some QNetwork... stuff for this, deal with local files vs remote resources, etc.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @JonB
      QFile has a static member to check for a file existence

      https://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)


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      JonBJ 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @JonB
        QFile has a static member to check for a file existence

        https://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)

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @J-Hilk
        I think QTextBrowser::source() looks in a variety of places (e.g. QTextBrowser::searchPaths()), beyond where QFile looks. I wanted to know if setSource() 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....

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved