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. How to make a loop in console application.
QtWS25 Last Chance

How to make a loop in console application.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 853 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.
  • M Offline
    M Offline
    maydin
    wrote on last edited by
    #1

    I have a WebSocket server and a client. I created a loop inside main function of client program after creating WebSocket. I want to read from console and send messages to server. But my client does not connect to my server until exec() function of QCoreApplication is called.

    What is the best or easiest way to do it.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can use a QTimer to periodically run some code.

      M 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        You can use a QTimer to periodically run some code.

        M Offline
        M Offline
        maydin
        wrote on last edited by
        #3

        @mrjj So if I singleshot to a function or lambda with QTimer, it will execute that when program reaches to exec()?

        mrjjM 1 Reply Last reply
        0
        • M maydin

          @mrjj So if I singleshot to a function or lambda with QTimer, it will execute that when program reaches to exec()?

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

          @maydin
          yes it should. but single shot only runs once and it sounded more you wanted to to
          more than one time. but else yes.

          M 1 Reply Last reply
          1
          • mrjjM mrjj

            @maydin
            yes it should. but single shot only runs once and it sounded more you wanted to to
            more than one time. but else yes.

            M Offline
            M Offline
            maydin
            wrote on last edited by maydin
            #5

            @mrjj Using readLine() causes application to wait until pressing enter. Therefore I solved problem by using Timer with low timeouts.

            But I am still not sure how Timer with 0 timeout runs my functions. Probably it waits until the function reaches to end before executing new one.

            mrjjM 1 Reply Last reply
            0
            • M maydin

              @mrjj Using readLine() causes application to wait until pressing enter. Therefore I solved problem by using Timer with low timeouts.

              But I am still not sure how Timer with 0 timeout runs my functions. Probably it waits until the function reaches to end before executing new one.

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

              @maydin
              well its single threaded so if u stay in a slot, im not sure it can even fire the new timeouts.
              At any rate, it should not run it overlapping.

              1 Reply Last reply
              0

              • Login

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