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. PyQT GUI freezes when I update several labels' text 30 times in second

PyQT GUI freezes when I update several labels' text 30 times in second

Scheduled Pinned Locked Moved Solved General and Desktop
pyqtpyqt5rospython
3 Posts 2 Posters 1.2k Views
  • 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.
  • F Offline
    F Offline
    farhadbat
    wrote on 15 Jul 2022, 19:53 last edited by
    #1

    I wrote a PyQT5 code. It connects to a ROS topic which produces messages with 30 Hz (30 messages in 1 second).

    This is an image from part of GUI:
    enter image description here

    When a user selects a gaze topic from Combobox, I call create_subscriber_gaze_information function with the help of connect signal for the combo box.

        # create ROS subscriber for gaze information if the value of its combo box changed
        ui.gaze_info_topic_name_value.activated.connect(create_subscriber_gaze_information)
    

    create_subscriber_gaze_information function creates a ROS subscriber that reads messages from the topic when it becomes available:

    def create_subscriber_gaze_information():
    
        # unsubscribe to the previous topic
        if ui.gaze_info_topic_name_value.ros_subs is not None:
            ui.gaze_info_topic_name_value.ros_subs.unregister()
    
        # create a subscriber
        ui.gaze_info_topic_name_value.ros_subs = rospy.Subscriber(
                                                            name=ui.gaze_info_topic_name_value.currentText(), 
                                                            data_class=gazesense_msgs.msg.TrackedUserArray, 
                                                            callback=show_gaze_information,
                                                            queue_size=1)
    

    Whenever a message becomes available (30 times per second), function show_gaze_information will be called automatically. This function updates the value of labels in GUI:

    def show_gaze_information(gaze_msg):
       
        if ui.groupBox_gaze.is_lock == True:
            return
    
        ui.groupBox_gaze.is_lock = True
    
        for person in gaze_msg.people:
            
            #################################
            # head info
            #################################
            # set value of head tranlation x
            ui.label_head_translation_x_value.setText("{}".format(person.tracking_info.head_pose.transform.translation.x))
            # set value of head tranlation y
            ui.label_head_translation_y_value.setText("{}".format(person.tracking_info.head_pose.transform.translation.y))
            # set value of head tranlation z
            ui.label_head_translation_z_value.setText("{}".format(person.tracking_info.head_pose.transform.translation.z))
            # set value of head rotation x
            ui.label_head_rotation_x_value.setText("{}".format(person.tracking_info.head_pose.transform.rotation.x))
            # set value of head rotation y
            ui.label_head_rotation_y_value.setText("{}".format(person.tracking_info.head_pose.transform.rotation.y))
            # set value of head rotation z
            ui.label_head_rotation_z_value.setText("{}".format(person.tracking_info.head_pose.transform.rotation.z))
            # set value of head rotation w
            ui.label_head_rotation_w_value.setText("{}".format(person.tracking_info.head_pose.transform.rotation.w))
            # set value of is lost
            ui.label_head_is_lost_value.setText("{}".format(person.tracking_info.head_pose.is_lost))
            #################################
            # left eye
            #################################
            # set value of left eye orgin x
            ui.label_left_eye_orgin_x_value.setText("{}".format(person.tracking_info.gaze.left_eye_ray.origin.x))
            # set value of left eye orgin y
            ui.label_left_eye_orgin_y_value.setText("{}".format(person.tracking_info.gaze.left_eye_ray.origin.y))
            # set value of left eye orgin z
            ui.label_left_eye_orgin_z_value.setText("{}".format(person.tracking_info.gaze.left_eye_ray.origin.z))
            # set value of left eye dir x
            ui.label_left_eye_dir_x_value.setText("{}".format(person.tracking_info.gaze.left_eye_ray.direction.x))
            # set value of left eye dir y
            ui.label_left_eye_dir_y_value.setText("{}".format(person.tracking_info.gaze.left_eye_ray.direction.y))
            # set value of left eye dir z
            ui.label_left_eye_dir_z_value.setText("{}".format(person.tracking_info.gaze.left_eye_ray.direction.z))
            # set value of left confidence
            ui.label_left_eye_conf_value.setText("{}".format(person.tracking_info.gaze.confidence_left.value))
            # set value of is lost
            ui.label_left_eye_is_lost_value.setText("{}".format(person.tracking_info.gaze.is_lost))
     
        ui.groupBox_gaze.is_lock = False
    

    However, the problem is that after running the program and selecting a topic from the combo box, it works for up to 10 seconds; after that, everything freezes.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      farhadbat
      wrote on 15 Jul 2022, 20:35 last edited by
      #3

      I found the problem.

      The problem is that I update labels in show_gaze_information.

      This function is a callback that is called when a message is published on the topic.

      To correct the code, in function show_gaze_information, the message should be stored in a variable. Nothing should be modified in UI.

      Then in main body of code, I added this part:

      # update gaze infor periodically
      timer_gaze = QtCore.QTimer()
      timer_gaze.timeout.connect(update_gaze_information)
      timer_gaze.setInterval(500)
      timer_gaze.start()
      

      This code periodically calls update_gaze_information every 0.5 seconds. Now, in this function, I update labels in the UI.

      1 Reply Last reply
      0
      • C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 15 Jul 2022, 19:56 last edited by
        #2

        @farhadbat said in PyQT GUI freezes when I update several labels' text 30 times in second:

        0 Hz (30 messages in 1 second).

        Nobody can read this so you don't need to update it every 1/30s - once or twice a second is enough.

        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
        • F Offline
          F Offline
          farhadbat
          wrote on 15 Jul 2022, 20:35 last edited by
          #3

          I found the problem.

          The problem is that I update labels in show_gaze_information.

          This function is a callback that is called when a message is published on the topic.

          To correct the code, in function show_gaze_information, the message should be stored in a variable. Nothing should be modified in UI.

          Then in main body of code, I added this part:

          # update gaze infor periodically
          timer_gaze = QtCore.QTimer()
          timer_gaze.timeout.connect(update_gaze_information)
          timer_gaze.setInterval(500)
          timer_gaze.start()
          

          This code periodically calls update_gaze_information every 0.5 seconds. Now, in this function, I update labels in the UI.

          1 Reply Last reply
          0

          1/3

          15 Jul 2022, 19:53

          • Login

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