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. Problem with QListView (PyQt5)
Qt 6.11 is out! See what's new in the release blog

Problem with QListView (PyQt5)

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 2.1k 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.
  • J Offline
    J Offline
    JIN81
    wrote on last edited by
    #1

    hello everyone Currently I am doing a simple chat socket program and I use QlistView to display the conversation but during the running process, I have the following problem:
    During the run, I have created a sub-thread inside to receive messages from the server as well as add that message to Qlistview, but when the message is added, the interface side does not update anything.
    2020-12-18_100039.png
    And only when the client imports the message and adds the message to Qlistview (this process is done in the main thread wrapped outside the sub-thread above), the message from the server will be added and displayed at the interface.
    2020-12-18_110828.png
    Is there any way I can add an item directly from the sub-thread and the interface is visible immediately?

    jsulmJ 1 Reply Last reply
    0
    • J JIN81

      hello everyone Currently I am doing a simple chat socket program and I use QlistView to display the conversation but during the running process, I have the following problem:
      During the run, I have created a sub-thread inside to receive messages from the server as well as add that message to Qlistview, but when the message is added, the interface side does not update anything.
      2020-12-18_100039.png
      And only when the client imports the message and adds the message to Qlistview (this process is done in the main thread wrapped outside the sub-thread above), the message from the server will be added and displayed at the interface.
      2020-12-18_110828.png
      Is there any way I can add an item directly from the sub-thread and the interface is visible immediately?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @JIN81 Qt is asynchronous, so usually there is no need for any threads when doing network programming. Why do you think you need a thread?
      Also, it is not supported to access UI classes outside from the GUI/main thread. If you want to use an additional thread then communicate with main thread via signals/slots instead of direct access to the GUI.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      3
      • jsulmJ jsulm

        @JIN81 Qt is asynchronous, so usually there is no need for any threads when doing network programming. Why do you think you need a thread?
        Also, it is not supported to access UI classes outside from the GUI/main thread. If you want to use an additional thread then communicate with main thread via signals/slots instead of direct access to the GUI.

        J Offline
        J Offline
        JIN81
        wrote on last edited by
        #3

        @jsulm Thanks for your reply. I need a thread to receive messages from the server and I'm a newbie, so I don't know that Qt is not supported to access UI from other thread :((

        jsulmJ 1 Reply Last reply
        0
        • J JIN81

          @jsulm Thanks for your reply. I need a thread to receive messages from the server and I'm a newbie, so I don't know that Qt is not supported to access UI from other thread :((

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JIN81 said in Problem with QListView (PyQt5):

          I need a thread to receive messages from the server and I'm a newbie

          Why do you think you need a thread for that?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          J 1 Reply Last reply
          2
          • jsulmJ jsulm

            @JIN81 said in Problem with QListView (PyQt5):

            I need a thread to receive messages from the server and I'm a newbie

            Why do you think you need a thread for that?

            J Offline
            J Offline
            JIN81
            wrote on last edited by
            #5

            @jsulm I use a thread that receives messages from the server and the other thread for sending messages from the client to the server. As the result, the program can receive and send messages at the same time. That reason why I think I need a thread

            jsulmJ 1 Reply Last reply
            0
            • J JIN81

              @jsulm I use a thread that receives messages from the server and the other thread for sending messages from the client to the server. As the result, the program can receive and send messages at the same time. That reason why I think I need a thread

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @JIN81 All this can be done without any threads! Qt is asynchronous, means: non blocking. There is really NO need for threads in your case, you're over-engineering things for no reason.
              Take a look at Qt networking examples.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J A 2 Replies Last reply
              2
              • jsulmJ jsulm

                @JIN81 All this can be done without any threads! Qt is asynchronous, means: non blocking. There is really NO need for threads in your case, you're over-engineering things for no reason.
                Take a look at Qt networking examples.

                J Offline
                J Offline
                JIN81
                wrote on last edited by
                #7

                @jsulm oh I got it. I wish I knew it earlier. Thank you !!!!

                1 Reply Last reply
                2
                • jsulmJ jsulm

                  @JIN81 All this can be done without any threads! Qt is asynchronous, means: non blocking. There is really NO need for threads in your case, you're over-engineering things for no reason.
                  Take a look at Qt networking examples.

                  A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on last edited by
                  #8

                  @jsulm said in Problem with QListView (PyQt5):

                  Qt is asynchronous, means: non blocking.

                  Could you elaborate , give an example , how "asynchronous" meas "non blocking"?

                  I believe the OP is asking how to implement two way , full duplex (send / receive same time ) communication.

                  Not how to run simplex -alternate between send then receive operations.

                  kshegunovK 1 Reply Last reply
                  0
                  • A Anonymous_Banned275

                    @jsulm said in Problem with QListView (PyQt5):

                    Qt is asynchronous, means: non blocking.

                    Could you elaborate , give an example , how "asynchronous" meas "non blocking"?

                    I believe the OP is asking how to implement two way , full duplex (send / receive same time ) communication.

                    Not how to run simplex -alternate between send then receive operations.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #9

                    @AnneRanch said in Problem with QListView (PyQt5):

                    Could you elaborate , give an example , how "asynchronous" meas "non blocking"?

                    It doesn't. However Qt prefers both asynchronous and non-blocking and is what it usually implements.

                    I believe the OP is asking how to implement two way , full duplex (send / receive same time ) communication.

                    Even if it were possible, it isn't enforceable. I'd be the same as requiring two threads to be executing on different cores - it is often the case, but certainly not a guarantee. There's layers upon layers, upon layers ... upon layers of software between you and the steel preventing you from achieving the god of thunder title.

                    Not how to run simplex -alternate between send then receive operations.

                    It's all buffered anyway. It's buffered in Qt, it's (usually) buffered in the kernel and/or the driver, and it may be buffered in the actual ethernet controller. So I really don't see how that should work ...

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    2

                    • Login

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