After using my Qt desktop application for a while and also using other applications simultaneously the stylesheet of my Qt desktop application changes.
-
@JonB I do agree with your point, but the problem is its a big code and I can't share it here. and I try making a small sample application on which it is not reproducing. I even can't post the screenshot of the problem here. but what the OP reported I am facing the exact same issue.
The real problem here is it is not 100% reproducible and there is no particular step. -
@SGaist So here is what happing in my class
- Inherited the QApplication class and in the constructor of the inherited class setStylesheet() by reading the QSS Stylesheet file.
getStyleSheetFile( QString fileName )
{
QFile file( fileName );
file.open( QFile::ReadOnly | QFile::Text );
QString styleSheet = QLatin1String( file.readAll() );
return styleSheet;
}- After this, we created so many other widgets and dialog and in some dialogs we set the styesheet where we want different stylesheet.
- Now when we run the application most of the time it is working fine and showing the stylesheets as set.
- but randomly sometimes it switch back to the qt default style and all the stylesheet is gone on almost all the widget.
Some key points here.
- After stylesheet is gone I opened a dilaog in which I set the stylesheet on QFrame/combobox/radiobutton/pushbutton. (which usually worked as setstylesheet ) is also not applying the stylesheet and showing the default Qt style and some places black or grey backgound. On some push button I even set the border to 0 px is also now showing the border as default style.
- I tried to reproduce this issue for about 8 hr and only able to reproduce 2 times. that too randomly.
Most Important one: our application support the batch execution of some backend operation which updates the UI and those backend operation is executed in a boost thread and through our custom observer design pattern/callbacks it update the UI elements like log widow some labels stylesheet. and mostly this issue reproduce when we perform this operation but its random. During normal operation of application it is working fine.
-
@SGaist .
my question is, even if this is happening then why this problem is not always, why this is random behavior. I know here we are talking about the threading which no one can predict. but still technically it should reproduce more often not 2 times in 8 hr.Does your "custom observer design pattern/callbacks" take that element into account ?
To be honest, I am not sure that it is not happening. But I think it's not otherwise this would be easily reproducible. we are just calling callbacks and there we are emitting the signals to the UI classes and updating the result on UI.Hypothetically even if due to this stylesheet is gone but it should recover when we open a new instance of the QDialog where we set the stylesheet agian.
Have you ever seen the same behavior?
-
There's the catch: calling functions on GUI elements from a different thread is currently in the "undefined behaviour" territory so you might just be lucky that it's not crashing your application at all.
What I would start with is to ensure that there's no direct call anywhere. Next step is to check what is connected and how the signals are emitted.
-
Hi @SGaist, thanks for your valuable feedback.
I resolved this issue.
Root-cause: Directly updating the UI components from the non-UI thread(aka main thread). As, the code size is really big it was really challenge to find out where it was happening.Does your "custom observer design pattern/callbacks" take that element into account ?
Yes, the framework support this thing, but somewhere it was broken. -
Glad you found out and fixed it !
Since you have it working now, please mark the thread as solved using so other forum users may know a solution has been found :-)
-
Right ! Your part was way longer than the original conversation 😅