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. Could not parse stylesheet of object QLabel
Forum Updated to NodeBB v4.3 + New Features

Could not parse stylesheet of object QLabel

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 6 Posters 6.7k 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.
  • Christian EhrlicherC Christian Ehrlicher

    @oBOXPOH said in Could not parse stylesheet of object QLabel:

    And I want to change style of some label in widget from thread.

    You must not modify the gui from any other thread than the main gui thread!

    O Offline
    O Offline
    oBOXPOH
    wrote on last edited by
    #3

    @Christian-Ehrlicher said in Could not parse stylesheet of object QLabel:

    @oBOXPOH said in Could not parse stylesheet of object QLabel:

    And I want to change style of some label in widget from thread.

    You must not modify the gui from any other thread than the main gui thread!

    Sorry for my explaining. I just want to change style with some request from thread. ANd I don't know, how I need to do it correctly.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      To communicate between thread you should use Signals and Slots.
      But based on your question I would ask that you think about if you really need a thread at all.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • O oBOXPOH

        @Christian-Ehrlicher said in Could not parse stylesheet of object QLabel:

        @oBOXPOH said in Could not parse stylesheet of object QLabel:

        And I want to change style of some label in widget from thread.

        You must not modify the gui from any other thread than the main gui thread!

        Sorry for my explaining. I just want to change style with some request from thread. ANd I don't know, how I need to do it correctly.

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

        @oBOXPOH
        @jsulm already answered your question for this over at https://forum.qt.io/topic/126942/qlabel-and-setstylesheet-exception/16

        @oBOXPOH It is not allowed to change UI from other threads than main (GUI) thread. Use signals/slots to communicate between threads (for example to trigger actions/ui changes).

        O 1 Reply Last reply
        0
        • JonBJ JonB

          @oBOXPOH
          @jsulm already answered your question for this over at https://forum.qt.io/topic/126942/qlabel-and-setstylesheet-exception/16

          @oBOXPOH It is not allowed to change UI from other threads than main (GUI) thread. Use signals/slots to communicate between threads (for example to trigger actions/ui changes).

          O Offline
          O Offline
          oBOXPOH
          wrote on last edited by oBOXPOH
          #6

          @JonB said in Could not parse stylesheet of object QLabel:

          @oBOXPOH
          @jsulm already answered your question for this over at https://forum.qt.io/topic/126942/qlabel-and-setstylesheet-exception/16

          @oBOXPOH It is not allowed to change UI from other threads than main (GUI) thread. Use signals/slots to communicate between threads (for example to trigger actions/ui changes).

          I tried to use signals and slot, but no success. Yes, now I haven't exception, but still haven't a style... I don't know, where and how I need to organize it for correct work.

          JonBJ Pl45m4P 2 Replies Last reply
          0
          • O oBOXPOH

            @JonB said in Could not parse stylesheet of object QLabel:

            @oBOXPOH
            @jsulm already answered your question for this over at https://forum.qt.io/topic/126942/qlabel-and-setstylesheet-exception/16

            @oBOXPOH It is not allowed to change UI from other threads than main (GUI) thread. Use signals/slots to communicate between threads (for example to trigger actions/ui changes).

            I tried to use signals and slot, but no success. Yes, now I haven't exception, but still haven't a style... I don't know, where and how I need to organize it for correct work.

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

            @oBOXPOH
            I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

            Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

            As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

            O 2 Replies Last reply
            2
            • O oBOXPOH

              @JonB said in Could not parse stylesheet of object QLabel:

              @oBOXPOH
              @jsulm already answered your question for this over at https://forum.qt.io/topic/126942/qlabel-and-setstylesheet-exception/16

              @oBOXPOH It is not allowed to change UI from other threads than main (GUI) thread. Use signals/slots to communicate between threads (for example to trigger actions/ui changes).

              I tried to use signals and slot, but no success. Yes, now I haven't exception, but still haven't a style... I don't know, where and how I need to organize it for correct work.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #8

              @oBOXPOH said in Could not parse stylesheet of object QLabel:

              I tried to use signals and slot, but no success

              What did you try?
              The idea is to send a signal from the second thread to trigger the style change in your GUI thread (so you avoid any conflict).


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • JonBJ JonB

                @oBOXPOH
                I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                O Offline
                O Offline
                oBOXPOH
                wrote on last edited by oBOXPOH
                #9

                @JonB said in Could not parse stylesheet of object QLabel:

                @oBOXPOH
                I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                Ok. But where can I find the main UI thread? Just I created slot for changing in MainWindow.cpp - and I still have my problem...

                Let me explain, what I have. I have MainWindow class, where I create 2 widgets. In the second widget I have some another widgets. When I activate button of the first widget, I start the thread, where I get requests to change some properties of widgets in second widget. For example, I can change text for labels, but can't change styles of labels.

                Pradeep P NP Pl45m4P 2 Replies Last reply
                0
                • O oBOXPOH

                  @JonB said in Could not parse stylesheet of object QLabel:

                  @oBOXPOH
                  I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                  Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                  As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                  Ok. But where can I find the main UI thread? Just I created slot for changing in MainWindow.cpp - and I still have my problem...

                  Let me explain, what I have. I have MainWindow class, where I create 2 widgets. In the second widget I have some another widgets. When I activate button of the first widget, I start the thread, where I get requests to change some properties of widgets in second widget. For example, I can change text for labels, but can't change styles of labels.

                  Pradeep P NP Offline
                  Pradeep P NP Offline
                  Pradeep P N
                  wrote on last edited by
                  #10

                  @oBOXPOH Can you have look at Signals/slots accross threads
                  Hope this might explain you a bit.

                  All the best.

                  Pradeep Nimbalkar.
                  Upvote the answer(s) that helped you to solve the issue...
                  Keep code clean.

                  1 Reply Last reply
                  1
                  • O oBOXPOH

                    @JonB said in Could not parse stylesheet of object QLabel:

                    @oBOXPOH
                    I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                    Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                    As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                    Ok. But where can I find the main UI thread? Just I created slot for changing in MainWindow.cpp - and I still have my problem...

                    Let me explain, what I have. I have MainWindow class, where I create 2 widgets. In the second widget I have some another widgets. When I activate button of the first widget, I start the thread, where I get requests to change some properties of widgets in second widget. For example, I can change text for labels, but can't change styles of labels.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by
                    #11

                    @oBOXPOH said in Could not parse stylesheet of object QLabel:

                    I start the thread

                    But do you really need the thread? You dont need an extra thread just to change widget properties


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    O 1 Reply Last reply
                    0
                    • Pl45m4P Pl45m4

                      @oBOXPOH said in Could not parse stylesheet of object QLabel:

                      I start the thread

                      But do you really need the thread? You dont need an extra thread just to change widget properties

                      O Offline
                      O Offline
                      oBOXPOH
                      wrote on last edited by
                      #12

                      @Pl45m4 said in Could not parse stylesheet of object QLabel:

                      @oBOXPOH said in Could not parse stylesheet of object QLabel:

                      I start the thread

                      But do you really need the thread? You dont need an extra thread just to change widget properties

                      I think, I need the thread, because I use QSerialPort to send and read messages. If I won't use the thread, I will block the widget, where I create the thread.

                      JonBJ 1 Reply Last reply
                      0
                      • O oBOXPOH

                        @Pl45m4 said in Could not parse stylesheet of object QLabel:

                        @oBOXPOH said in Could not parse stylesheet of object QLabel:

                        I start the thread

                        But do you really need the thread? You dont need an extra thread just to change widget properties

                        I think, I need the thread, because I use QSerialPort to send and read messages. If I won't use the thread, I will block the widget, where I create the thread.

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

                        @oBOXPOH
                        No, Qt classes like serial ports are asynchronous. So long as you use the signals/slots, not blocking calls. It seems unlikely you need a secondary thread, and without multiple threads your life will be much easier....

                        Pl45m4P 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @oBOXPOH
                          No, Qt classes like serial ports are asynchronous. So long as you use the signals/slots, not blocking calls. It seems unlikely you need a secondary thread, and without multiple threads your life will be much easier....

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by Pl45m4
                          #14

                          @oBOXPOH

                          If you are currently using the blocking QSerialPort approach (with waitFor...()), have a look at the non-blocking example:

                          • https://doc.qt.io/qt-5/qtserialport-terminal-example.html

                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          JonBJ 1 Reply Last reply
                          0
                          • Pl45m4P Pl45m4

                            @oBOXPOH

                            If you are currently using the blocking QSerialPort approach (with waitFor...()), have a look at the non-blocking example:

                            • https://doc.qt.io/qt-5/qtserialport-terminal-example.html
                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #15

                            @Pl45m4 said in Could not parse stylesheet of object QLabel:

                            @JonB said in Could not parse stylesheet of object QLabel:

                            serial ports are asynchronous

                            Not always. There is a blocking and non-blocking QSerialPort appraoch.

                            I'm not following you? I wrote

                            No, Qt classes like serial ports are asynchronous. So long as you use the signals/slots, not blocking calls.

                            The calls are asynchronous. If you choose to waitFor..() you are choosing to block, by making your code synchronous. What are you saying any different from that?

                            1 Reply Last reply
                            0
                            • JonBJ JonB

                              @oBOXPOH
                              I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                              Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                              As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                              O Offline
                              O Offline
                              oBOXPOH
                              wrote on last edited by
                              #16

                              @JonB said in Could not parse stylesheet of object QLabel:

                              @oBOXPOH
                              I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                              Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                              As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                              I can't to win my problem with styleSheet... I even deleted thread. Let me explain what I have done.
                              styleSheet.png
                              When I click to button1_1, I emit some signal from widget1 to slot of widget2. In slot of widget2 I emit some signal to slot of created some class inside widget2. Inside this class I have a loop with signals/slots. And during this loop I need to change styles of widgets inside widget2 (label2_1). When I need to change style of label, I emit signal from class to slot of widget2 and call method of, for example, widget2_1 in order to change the style of label, but, without exception, I get "Could not parse stylesheet of object QLabel(0xf66ad8)". I tried many things, but still no success.

                              Hope for your help! Thank you in advance!

                              mrjjM 1 Reply Last reply
                              0
                              • O oBOXPOH

                                @JonB said in Could not parse stylesheet of object QLabel:

                                @oBOXPOH
                                I assume you know how to write signals & slots already. If not, look at @Christian-Ehrlicher's link.

                                Define a signal in the thread. emit the signal from the thread, with whatever parameters are desired. Define a slot in the main UI thread. In the UI connect() the thread's signal to the UI's slot. There act on the signal and its parameters to execute the pLabel->setStyleSheet().

                                As @Christian-Ehrlicher said, whether you need or should have any non-UI thread is another question. Most newcomers seem to think they need threads, when they do not.

                                I can't to win my problem with styleSheet... I even deleted thread. Let me explain what I have done.
                                styleSheet.png
                                When I click to button1_1, I emit some signal from widget1 to slot of widget2. In slot of widget2 I emit some signal to slot of created some class inside widget2. Inside this class I have a loop with signals/slots. And during this loop I need to change styles of widgets inside widget2 (label2_1). When I need to change style of label, I emit signal from class to slot of widget2 and call method of, for example, widget2_1 in order to change the style of label, but, without exception, I get "Could not parse stylesheet of object QLabel(0xf66ad8)". I tried many things, but still no success.

                                Hope for your help! Thank you in advance!

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

                                @oBOXPOH

                                Hi
                                can you show the complete stylesheet?
                                as that errors says it cannot be parsed so it might just be a case of invalid syntax.

                                O 2 Replies Last reply
                                1
                                • mrjjM mrjj

                                  @oBOXPOH

                                  Hi
                                  can you show the complete stylesheet?
                                  as that errors says it cannot be parsed so it might just be a case of invalid syntax.

                                  O Offline
                                  O Offline
                                  oBOXPOH
                                  wrote on last edited by oBOXPOH
                                  #18

                                  @mrjj said in Could not parse stylesheet of object QLabel:

                                  @oBOXPOH

                                  Hi
                                  can you show the complete stylesheet?
                                  as that errors says it cannot be parsed so it might just be a case of invalid syntax.

                                  pLabel->setStyleSheet(QString(pCChar_GreenStatusStyle));
                                  
                                  const char *pCChar_GreenStatusStyle = "{ color: green; font-weight: bold; }";
                                  
                                  1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @oBOXPOH

                                    Hi
                                    can you show the complete stylesheet?
                                    as that errors says it cannot be parsed so it might just be a case of invalid syntax.

                                    O Offline
                                    O Offline
                                    oBOXPOH
                                    wrote on last edited by oBOXPOH
                                    #19

                                    @mrjj said in Could not parse stylesheet of object QLabel:

                                    @oBOXPOH

                                    Hi
                                    can you show the complete stylesheet?
                                    as that errors says it cannot be parsed so it might just be a case of invalid syntax.

                                    You are right, by the way! I need:

                                    const char* *pCChar_GreenStatusStyle = "QLabel { color: green; font-weight: bold; }";

                                    And now it works finally! By the way, I deleted this QLabel word because I tried to find an error.

                                    Anyway, If someone has such problem, try to use only signals and slots like I used (image and description above) and check your styles. For serialPorts, for example, don't use threads, because else you will be in trouble.

                                    JonBJ 1 Reply Last reply
                                    1
                                    • O oBOXPOH

                                      @mrjj said in Could not parse stylesheet of object QLabel:

                                      @oBOXPOH

                                      Hi
                                      can you show the complete stylesheet?
                                      as that errors says it cannot be parsed so it might just be a case of invalid syntax.

                                      You are right, by the way! I need:

                                      const char* *pCChar_GreenStatusStyle = "QLabel { color: green; font-weight: bold; }";

                                      And now it works finally! By the way, I deleted this QLabel word because I tried to find an error.

                                      Anyway, If someone has such problem, try to use only signals and slots like I used (image and description above) and check your styles. For serialPorts, for example, don't use threads, because else you will be in trouble.

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

                                      @oBOXPOH said in Could not parse stylesheet of object QLabel:

                                      I need:
                                      const char* *pCChar_GreenStatusStyle = "QLabel { color: green; font-weight: bold; }";

                                      I am surprised at this! That is a char **. But if you say that is required to work.....

                                      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