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. setStyleSheet() error help
Forum Updated to NodeBB v4.3 + New Features

setStyleSheet() error help

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 4 Posters 5.0k Views 4 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 JonB

    Code uses setStyleSheet(), both from external file and in-line. When I --- or worse still, my end user --- makes a syntactic mistake, like:

    abc  /* missing { */
      def: ghi;
    }
    
    ...
    

    Qt spits out loads of qdebug() << "Could not parse stylesheet of object 0x5615a18bd6b0" (doubtless falling over in many later objects because of error somewhere earler).

    Apart from the fact that setStyleSheet() doesn't return a result or have callbacks when something goes wrong, I (my end user) has no idea where the syntax error is, and an external stylesheet can be large.... Any chance of finding where the errors occur (e.g. a line number or context)?

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    @JNBarchan
    no.
    Stylesheet parsing isn't part of any public API.

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    JonBJ 1 Reply Last reply
    2
    • raven-worxR raven-worx

      @JNBarchan
      no.
      Stylesheet parsing isn't part of any public API.

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

      @raven-worx
      :) OK, so not much alternative to telling them to look through it line-by-line then.... (Or, translate as "send it to me and I'll have to look through it line-by-line for you..."!)

      raven-worxR 1 Reply Last reply
      0
      • JonBJ JonB

        @raven-worx
        :) OK, so not much alternative to telling them to look through it line-by-line then.... (Or, translate as "send it to me and I'll have to look through it line-by-line for you..."!)

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #4

        @JNBarchan
        or pre-parse the stylesheet data (e.g. using lex/yacc) to catch at least the most obvious syntax errors.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Hi
          Just as a note
          Even if
          "C:\Qt\5.9.1\msvc2015_64\include\QtGui\5.9.1\QtGui\private\qcssparser_p.h"
          was part of the public API, im not sure it can say the where in file
          since even the onboard editor just say "Invalid"
          alt text

          JonBJ 1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Just as a note
            Even if
            "C:\Qt\5.9.1\msvc2015_64\include\QtGui\5.9.1\QtGui\private\qcssparser_p.h"
            was part of the public API, im not sure it can say the where in file
            since even the onboard editor just say "Invalid"
            alt text

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

            @mrjj
            When I write CSS file in Visual Studio(!), it parses them syntactically and squiggles where there's an error, just as it would with HTML, C++, .... Just saying! :)

            mrjjM 1 Reply Last reply
            0
            • JonBJ JonB

              @mrjj
              When I write CSS file in Visual Studio(!), it parses them syntactically and squiggles where there's an error, just as it would with HTML, C++, .... Just saying! :)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @JNBarchan
              Yep, i was also a bit surprised that there were no better
              error feedback than "invalid" as when you have a huge sheets
              its can be hard to find.

              I was wondering if Qt syntax is a true subset of full CSS and hence
              we could use a commandline validator to spot errors.

              JonBJ 1 Reply Last reply
              0
              • mrjjM mrjj

                @JNBarchan
                Yep, i was also a bit surprised that there were no better
                error feedback than "invalid" as when you have a huge sheets
                its can be hard to find.

                I was wondering if Qt syntax is a true subset of full CSS and hence
                we could use a commandline validator to spot errors.

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

                @mrjj
                Yep. I liked @raven-worx 's:

                pre-parse the stylesheet data (e.g. using lex/yacc)

                Presumably he has in mind that I write the lex/yacc rules... ;-)

                mrjjM raven-worxR 2 Replies Last reply
                0
                • JonBJ JonB

                  @mrjj
                  Yep. I liked @raven-worx 's:

                  pre-parse the stylesheet data (e.g. using lex/yacc)

                  Presumably he has in mind that I write the lex/yacc rules... ;-)

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #9

                  @JNBarchan
                  Hehe well i guess if u know lex it's not huge effort needed but i
                  have no clue as i have never used them.

                  Anyway, i wanted to run
                  http://csstidy.sourceforge.net/
                  and see if it would report bad ccs. (with line no)

                  JonBJ 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @JNBarchan
                    Hehe well i guess if u know lex it's not huge effort needed but i
                    have no clue as i have never used them.

                    Anyway, i wanted to run
                    http://csstidy.sourceforge.net/
                    and see if it would report bad ccs. (with line no)

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

                    @mrjj
                    I wouldn't be interested in anything other than whatever Qt setStyleSheet does or does not accept, regardless of whether it's "right" or "wrong".

                    For the record, this question is inspired as a consequence of my post https://forum.qt.io/topic/84022/code-for-qinstallmessagehandler. I have been finding that setStyleSheet must be hitting qDebug() lines wherever it does not like what it sees.... If that could/happened to include info on what was wrong where, it would suffice for me.

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #11

                      Hi
                      me neither but if Q CSS is a true subset, any css validator will work :)
                      Never got around to test it though.

                      Sounds like something to check. You are right that it can say it found error for some Object but
                      it lacks even the basic info on what object so i don't have high hopes.
                      But ill cross fingers you find something interesting :)

                      JonBJ 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        Hi
                        me neither but if Q CSS is a true subset, any css validator will work :)
                        Never got around to test it though.

                        Sounds like something to check. You are right that it can say it found error for some Object but
                        it lacks even the basic info on what object so i don't have high hopes.
                        But ill cross fingers you find something interesting :)

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

                        @mrjj said in setStyleSheet() error help:

                        Hi
                        me neither but if Q CSS is a true subset, any css validator will work :)

                        No, because the full CSS validator would allow through loads of things which the subset does not. And if Q CSS were a superset, it would object to stuff which was allowed. :)

                        mrjjM 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @mrjj said in setStyleSheet() error help:

                          Hi
                          me neither but if Q CSS is a true subset, any css validator will work :)

                          No, because the full CSS validator would allow through loads of things which the subset does not. And if Q CSS were a superset, it would object to stuff which was allowed. :)

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @JNBarchan
                          Just tested it and its not a true subset.
                          it had syntaxes the validator clearly didn't like even if valid for Qt.
                          So it was just a pipe dream.

                          1 Reply Last reply
                          0
                          • JonBJ JonB

                            @mrjj
                            Yep. I liked @raven-worx 's:

                            pre-parse the stylesheet data (e.g. using lex/yacc)

                            Presumably he has in mind that I write the lex/yacc rules... ;-)

                            raven-worxR Offline
                            raven-worxR Offline
                            raven-worx
                            Moderators
                            wrote on last edited by raven-worx
                            #14

                            @JNBarchan said in setStyleSheet() error help:

                            Presumably he has in mind that I write the lex/yacc rules... ;-)

                            well i've posted the rules along with my post?!
                            I've written a QSS parser myself based on common CSS lex/yacc rules found in some github repository. And it worked pretty well. It's of course also capable of showing you the exact line of the error and what it expected instead of the error.

                            And the hardest part of lex/yacc is the writing of the rules, which you can take over. The C harness is mostly the same all the time and can be found in many examples on the web.

                            QSS is not compatible to CSS. It just uses most of it's syntax ;)
                            But actually this is just some adaption of the rules which shouldn't also be a big issue once you get used to the rules syntax.

                            And also as a side note, the QSS parser has some issues/bugs and is by far not perfect. This results in that syntactically QSS is not parsed entirely.

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            mrjjM JonBJ 2 Replies Last reply
                            1
                            • raven-worxR raven-worx

                              @JNBarchan said in setStyleSheet() error help:

                              Presumably he has in mind that I write the lex/yacc rules... ;-)

                              well i've posted the rules along with my post?!
                              I've written a QSS parser myself based on common CSS lex/yacc rules found in some github repository. And it worked pretty well. It's of course also capable of showing you the exact line of the error and what it expected instead of the error.

                              And the hardest part of lex/yacc is the writing of the rules, which you can take over. The C harness is mostly the same all the time and can be found in many examples on the web.

                              QSS is not compatible to CSS. It just uses most of it's syntax ;)
                              But actually this is just some adaption of the rules which shouldn't also be a big issue once you get used to the rules syntax.

                              And also as a side note, the QSS parser has some issues/bugs and is by far not perfect. This results in that syntactically QSS is not parsed entirely.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              @raven-worx
                              Ohh, that i completely miss. (and poster to)
                              Thank you. That makes far easier. The rules can be used as is, or need some fiddling ?
                              I had hoped QSS was a CSS subset as to cheat at bit :)

                              raven-worxR 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @raven-worx
                                Ohh, that i completely miss. (and poster to)
                                Thank you. That makes far easier. The rules can be used as is, or need some fiddling ?
                                I had hoped QSS was a CSS subset as to cheat at bit :)

                                raven-worxR Offline
                                raven-worxR Offline
                                raven-worx
                                Moderators
                                wrote on last edited by
                                #16

                                @mrjj said in setStyleSheet() error help:

                                The rules can be used as is, or need some fiddling ?

                                they should be possible to use right away. But some parts might be missing, like the pseudo-control names and pseudo-states of the QWidget controls. And also the property selector for string-lists ~= is not part of CSS IIRC.

                                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                If you have a question please use the forum so others can benefit from the solution in the future

                                1 Reply Last reply
                                1
                                • raven-worxR raven-worx

                                  @JNBarchan said in setStyleSheet() error help:

                                  Presumably he has in mind that I write the lex/yacc rules... ;-)

                                  well i've posted the rules along with my post?!
                                  I've written a QSS parser myself based on common CSS lex/yacc rules found in some github repository. And it worked pretty well. It's of course also capable of showing you the exact line of the error and what it expected instead of the error.

                                  And the hardest part of lex/yacc is the writing of the rules, which you can take over. The C harness is mostly the same all the time and can be found in many examples on the web.

                                  QSS is not compatible to CSS. It just uses most of it's syntax ;)
                                  But actually this is just some adaption of the rules which shouldn't also be a big issue once you get used to the rules syntax.

                                  And also as a side note, the QSS parser has some issues/bugs and is by far not perfect. This results in that syntactically QSS is not parsed entirely.

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

                                  @raven-worx said in setStyleSheet() error help:

                                  @JNBarchan said in setStyleSheet() error help:

                                  Presumably he has in mind that I write the lex/yacc rules... ;-)

                                  well i've posted the rules along with my post?!

                                  I too missed that --- I assumed your hyperlinks on lex/yacc pointed to help for lex & yacc, now I see they are the rule files for Q CSS, got it!

                                  Now I presume that Qt is actually using that lex/yacc to do its parsing. I believe that when lex/yacc fails to parse the input and falls into error case --- which I assume is where the qDebug() is in source code --- it does include filename/line number/context in input where failure occurred. It would be nice if the qDebug() message included that, it's all I need. This probably isn't the place to ask for that, just wondered if you can do magic and make it happen... :)

                                  raven-worxR 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @raven-worx said in setStyleSheet() error help:

                                    @JNBarchan said in setStyleSheet() error help:

                                    Presumably he has in mind that I write the lex/yacc rules... ;-)

                                    well i've posted the rules along with my post?!

                                    I too missed that --- I assumed your hyperlinks on lex/yacc pointed to help for lex & yacc, now I see they are the rule files for Q CSS, got it!

                                    Now I presume that Qt is actually using that lex/yacc to do its parsing. I believe that when lex/yacc fails to parse the input and falls into error case --- which I assume is where the qDebug() is in source code --- it does include filename/line number/context in input where failure occurred. It would be nice if the qDebug() message included that, it's all I need. This probably isn't the place to ask for that, just wondered if you can do magic and make it happen... :)

                                    raven-worxR Offline
                                    raven-worxR Offline
                                    raven-worx
                                    Moderators
                                    wrote on last edited by
                                    #18

                                    @JNBarchan
                                    those are the rule files for CSS 2.1, not directly for QSS. And Qt doesn't use lex/yacc internally AFAIK.
                                    See my previous post.

                                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                    If you have a question please use the forum so others can benefit from the solution in the future

                                    JonBJ 1 Reply Last reply
                                    1
                                    • raven-worxR raven-worx

                                      @JNBarchan
                                      those are the rule files for CSS 2.1, not directly for QSS. And Qt doesn't use lex/yacc internally AFAIK.
                                      See my previous post.

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

                                      @raven-worx
                                      Ah I see, again I misunderstood! Thanks.

                                      1 Reply Last reply
                                      0
                                      • V Offline
                                        V Offline
                                        Vadi2
                                        wrote on last edited by
                                        #20

                                        I'd be interested in a way to get more helpful error messages as well.

                                        1 Reply Last reply
                                        1

                                        • Login

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