setStyleSheet() error help
-
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)? -
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)?@JNBarchan
no.
Stylesheet parsing isn't part of any public API. -
@JNBarchan
no.
Stylesheet parsing isn't part of any public API.@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-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..."!) -
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"
-
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"
-
@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! :)@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. -
@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. -
@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... ;-)@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) -
@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)@mrjj
I wouldn't be interested in anything other than whatever QtsetStyleSheet
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 hittingqDebug()
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. -
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 :) -
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 :)@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. :)
-
@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. :)
@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. -
@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... ;-)@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.
-
@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.
@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-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 :)@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. -
@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.
@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 theqDebug()
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-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 theqDebug()
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... :)@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. -
@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.@raven-worx
Ah I see, again I misunderstood! Thanks.