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.
  • 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