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. Qt Thread architecture
Qt 6.11 is out! See what's new in the release blog

Qt Thread architecture

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 1.8k 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.
  • K king558

    @SGaist

    Hello, I forgot to mentions about communication with Server A using third libraries, so it need a loop, check in every loop the data is coming in. So there must a thread for the communication with Server A.

    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Well, QLocalServer is also asynchronous. Which 3rd party library do you need to use ? You are showing none in your code sample.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • K king558

      @SGaist

      Hello, I forgot to mentions about communication with Server A using third libraries, so it need a loop, check in every loop the data is coming in. So there must a thread for the communication with Server A.

      K Offline
      K Offline
      king558
      wrote on last edited by
      #5

      @king558

      its a tdlib on github, from its I take datas, it runs with a loop, check its state and give the content to main thread to parse the content and forward to Server B

      Christian EhrlicherC 1 Reply Last reply
      0
      • K king558

        @king558

        its a tdlib on github, from its I take datas, it runs with a loop, check its state and give the content to main thread to parse the content and forward to Server B

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #6

        The provided code does nothing - at least what not you expect. It neither shares some data nor is the mutex useful at all. Receive the data, emit a signal and connect it to a slot in your main thread if you need a separate thread at all - your example code does not.

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

        SGaistS K 2 Replies Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          The provided code does nothing - at least what not you expect. It neither shares some data nor is the mutex useful at all. Receive the data, emit a signal and connect it to a slot in your main thread if you need a separate thread at all - your example code does not.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #7

          tdlib ? Are you writing a client for telegram ? If so, there are Qt based libraries for that which might be simpler to use in your case.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #8

            It is not good style (anymore) to override QThread::run(). Have a look at the documentation for QThread how to create a worker thread.

            There is an even better approach for your use case. Just create a plain old QThread object and start it. It will run its own event loop. You should probably not run an infinite loop to takes up every CPU cycle of one core. Instead, start a QTimer (with a low timeout) in this thread to call your external library and check for new data.

            Also, try to avoid QMutex. Synchronization between threads is slow. Furthermore, in your small code example only a single object has access to the mutex. This means that you don't need it.

            K 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              The provided code does nothing - at least what not you expect. It neither shares some data nor is the mutex useful at all. Receive the data, emit a signal and connect it to a slot in your main thread if you need a separate thread at all - your example code does not.

              K Offline
              K Offline
              king558
              wrote on last edited by
              #9

              @Christian-Ehrlicher

              Really? Could you please provide me the name or github link?

              SGaistS 2 Replies Last reply
              0
              • K king558

                @Christian-Ehrlicher

                Really? Could you please provide me the name or github link?

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @king558 where you in fact asking me for a link ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                K 1 Reply Last reply
                0
                • S SimonSchroeder

                  It is not good style (anymore) to override QThread::run(). Have a look at the documentation for QThread how to create a worker thread.

                  There is an even better approach for your use case. Just create a plain old QThread object and start it. It will run its own event loop. You should probably not run an infinite loop to takes up every CPU cycle of one core. Instead, start a QTimer (with a low timeout) in this thread to call your external library and check for new data.

                  Also, try to avoid QMutex. Synchronization between threads is slow. Furthermore, in your small code example only a single object has access to the mutex. This means that you don't need it.

                  K Offline
                  K Offline
                  king558
                  wrote on last edited by
                  #11

                  @SimonSchroeder said in Qt Thread architecture:

                  It is not good style (anymore) to override QThread::run(). Have a look at the documentation for QThread how to create a worker thread.

                  There is an even better approach for your use case. Just create a plain old QThread object and start it. It will run its own event loop. You should probably not run an infinite loop to takes up every CPU cycle of one core. Instead, start a QTimer (with a low timeout) in this thread to call your external library and check for new data.

                  Also, try to avoid QMutex. Synchronization between threads is slow. Furthermore, in your small code example only a single object has access to the mutex. This means that you don't need it.

                  Thx you, I have a infinite run loop, that need to check the state of the connection and data received. In this case is movetoThread also possible or override QThread::run is best fot fit?

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    @king558 where you in fact asking me for a link ?

                    K Offline
                    K Offline
                    king558
                    wrote on last edited by
                    #12

                    @SGaist said in Qt Thread architecture:

                    @king558 where you in fact asking me for a link ?

                    You said, there are qt based library for telegram, so I asked you for the name if it is third party library and where I can find it

                    1 Reply Last reply
                    0
                    • K king558

                      @Christian-Ehrlicher

                      Really? Could you please provide me the name or github link?

                      SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      @king558 said in Qt Thread architecture:

                      @Christian-Ehrlicher

                      Really? Could you please provide me the name or github link?

                      I don't want to nitpick but you literally tagged @Christian-Ehrlicher with that request hence my question.

                      Anyway, the first hit when searching Qt telegram client brings you this https://github.com/Kaffeine/telegram-qt

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      K 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        @king558 said in Qt Thread architecture:

                        @Christian-Ehrlicher

                        Really? Could you please provide me the name or github link?

                        I don't want to nitpick but you literally tagged @Christian-Ehrlicher with that request hence my question.

                        Anyway, the first hit when searching Qt telegram client brings you this https://github.com/Kaffeine/telegram-qt

                        K Offline
                        K Offline
                        king558
                        wrote on last edited by
                        #14

                        @SGaist

                        Thx you for link, it was my mistake.

                        1 Reply Last reply
                        0
                        • K king558 has marked this topic as solved on

                        • Login

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