Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. PyQt6: QSvgWidget does not render when loading a QByteArray instead of a file

PyQt6: QSvgWidget does not render when loading a QByteArray instead of a file

Scheduled Pinned Locked Moved Unsolved Qt for Python
14 Posts 2 Posters 1.2k Views
  • 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.
  • E Offline
    E Offline
    ErwanM
    wrote on last edited by
    #5

    @JonB many thanks for your links.
    My own search leaded me to similar answers that where written for Pyside2 or PyQt5 but none of them was really relevant for my case.

    I can now go further and make my SVG produced dynamically by a refresh function. I will see if loading another svg will trigger the rendering. Yous links could be interesting if rendering does not occur in that case.

    Concerning utf-8, no one should use any other encoding now for python scripts, svg or any text file unless having a very good reason to use another encoding. With windows API, utf16-le is also common but it's a niche.

    JonBJ 1 Reply Last reply
    0
    • E ErwanM

      @JonB many thanks for your links.
      My own search leaded me to similar answers that where written for Pyside2 or PyQt5 but none of them was really relevant for my case.

      I can now go further and make my SVG produced dynamically by a refresh function. I will see if loading another svg will trigger the rendering. Yous links could be interesting if rendering does not occur in that case.

      Concerning utf-8, no one should use any other encoding now for python scripts, svg or any text file unless having a very good reason to use another encoding. With windows API, utf16-le is also common but it's a niche.

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

      @ErwanM
      Technically this has nothing to do with PySide, PyQt or Python. I imagine you would get same problem if you sent it from C++ or wherever with preceding whitespace, or if you edited your external file and put a blank line at the very start.

      E 1 Reply Last reply
      0
      • JonBJ JonB

        @ErwanM
        Technically this has nothing to do with PySide, PyQt or Python. I imagine you would get same problem if you sent it from C++ or wherever with preceding whitespace, or if you edited your external file and put a blank line at the very start.

        E Offline
        E Offline
        ErwanM
        wrote on last edited by
        #7

        @JonB the link to python comes from the here string syntax: the string start just after the triple quote and not at the next line.
        In others language like perl, the here string start at the next line to preserve the first line indent.

        C++ 11 introduced a here string like construction and, again, the raw string start at the next line.

        So this error is in part due to the language syntax for here string.

        1 Reply Last reply
        0
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #8

          Well if you don't know whether your language happens to put in or not put a linefeed in whatever string literal construct you choose to use that is a problem. But the error here is the due to the parsing of the XML requiring there be no leading whitespace, that's all I'm saying.

          @ErwanM said in PyQt6: QSvgWidget does not render when loading a QByteArray instead of a file:

          C++ 11 introduced a here string like construction and, again, the raw string start at the next line.

          Pardon/really? Not to the best of my knowledge, but I may be at fault. Which construct are you talking about (example please) and where do you claim " the raw string start at the next line" is the case? The C++ literals I can think of (e.g. R"(...)") would not only "start at the next line", the initial line where the string literal opener is placed would "count" towards the string content. Perl or Linux shells have the "here document", and that indeed does not count the start line, only the following line below, but that's not C++.

          E 1 Reply Last reply
          0
          • JonBJ JonB

            Well if you don't know whether your language happens to put in or not put a linefeed in whatever string literal construct you choose to use that is a problem. But the error here is the due to the parsing of the XML requiring there be no leading whitespace, that's all I'm saying.

            @ErwanM said in PyQt6: QSvgWidget does not render when loading a QByteArray instead of a file:

            C++ 11 introduced a here string like construction and, again, the raw string start at the next line.

            Pardon/really? Not to the best of my knowledge, but I may be at fault. Which construct are you talking about (example please) and where do you claim " the raw string start at the next line" is the case? The C++ literals I can think of (e.g. R"(...)") would not only "start at the next line", the initial line where the string literal opener is placed would "count" towards the string content. Perl or Linux shells have the "here document", and that indeed does not count the start line, only the following line below, but that's not C++.

            E Offline
            E Offline
            ErwanM
            wrote on last edited by
            #9

            @JonB as many people do, i don't make use of a single language but many of them from several assembly languages to high level ones like perl, php, javascript, SQL or even bash/cmd.

            When programmers have to switch between many languages, any particularity represent a potential trap. Python here string syntax is one of them because it's not the common way to do it.

            JonBJ 1 Reply Last reply
            0
            • E ErwanM

              @JonB as many people do, i don't make use of a single language but many of them from several assembly languages to high level ones like perl, php, javascript, SQL or even bash/cmd.

              When programmers have to switch between many languages, any particularity represent a potential trap. Python here string syntax is one of them because it's not the common way to do it.

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

              @ErwanM
              I asked you a simple question. You stated:

              C++ 11 introduced a here string like construction and, again, the raw string start at the next line.

              And I said I did not think so. Could you kindly provide an example of whatever you mean by "a here string like construction" in C++ which has "the raw string start at the next line"? Because the only think I can think you might mean is the R"(...)" construction and as I said that does not "start on the next line", it started immediately after the opening R"(, just as is does for the Python """.

              This is not a criticism of you, and of course your swapping between multiple languages (just as I do) is an understandable source of confusion. It is merely an attempt to clarify or put the record straight for other readers of your earlier statement. We like to keep things accurate on this site :)

              E 1 Reply Last reply
              0
              • JonBJ JonB

                @ErwanM
                I asked you a simple question. You stated:

                C++ 11 introduced a here string like construction and, again, the raw string start at the next line.

                And I said I did not think so. Could you kindly provide an example of whatever you mean by "a here string like construction" in C++ which has "the raw string start at the next line"? Because the only think I can think you might mean is the R"(...)" construction and as I said that does not "start on the next line", it started immediately after the opening R"(, just as is does for the Python """.

                This is not a criticism of you, and of course your swapping between multiple languages (just as I do) is an understandable source of confusion. It is merely an attempt to clarify or put the record straight for other readers of your earlier statement. We like to keep things accurate on this site :)

                E Offline
                E Offline
                ErwanM
                wrote on last edited by
                #11

                @JonB yes, you're right. C++ raw string literals start just after the first delimiter.

                Coupled with the fact that end delimiter can be on the same line as content, this makes two traps instead of one.

                These characteristics allow the construction of a one line raw string but this is not the common case i think.

                In the examples i found on Stack overflow, i've seen xml files, starting at the next line after the start delimiter.

                This is just a banana peel that python and C++ developers have left to make developer slip away.

                JonBJ 1 Reply Last reply
                0
                • E ErwanM

                  @JonB yes, you're right. C++ raw string literals start just after the first delimiter.

                  Coupled with the fact that end delimiter can be on the same line as content, this makes two traps instead of one.

                  These characteristics allow the construction of a one line raw string but this is not the common case i think.

                  In the examples i found on Stack overflow, i've seen xml files, starting at the next line after the start delimiter.

                  This is just a banana peel that python and C++ developers have left to make developer slip away.

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

                  @ErwanM said in PyQt6: QSvgWidget does not render when loading a QByteArray instead of a file:

                  In the examples i found on Stack overflow, i've seen xml files, starting at the next line after the start delimiter.

                  That would be interesting. Any links? Because as we have discovered if they start with the <?xml declaration that must be in very first character position, no whitespace/newline character before. OTOH if they do not have this declaration, e.g. they just start with <SomeNode>, then per the XML spec that can be preceded by whitespace (e.g. newline), it is only the <?xml which has to appear from first character spot, maybe that is what you saw?

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    ErwanM
                    wrote on last edited by
                    #13

                    In this thread, most of people are using raw string literal as i do with line breaks around the raw string: https://stackoverflow.com/questions/1135841/how-to-write-a-multi-line-string-literal

                    JonBJ 1 Reply Last reply
                    0
                    • E ErwanM

                      In this thread, most of people are using raw string literal as i do with line breaks around the raw string: https://stackoverflow.com/questions/1135841/how-to-write-a-multi-line-string-literal

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

                      @ErwanM
                      Yes, the ones there using the R"(-type construct are shown having leading & trailing newlines which will be in the resulting string. One guy does even say

                      All the spaces and indentation and the newlines in the string are preserved.

                      That's up to them for their examples where it doesn't matter. In your case of <?xml we simply cannot afford that.

                      The one which starts

                      std::string index_html=R"html(
                      <!DOCTYPE html>
                      

                      would have a newline before the <!DOCTYPE html>, but maybe that is allowed, unlike for <?xml. Or maybe it isn't allowed either and they didn't check!

                      Anyway, there we are, that's just how it is.

                      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