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.
Forum Updated to NodeBB v4.3 + New Features

How to make a loop in console application.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 919 Views 1 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.
  • M Offline
    M Offline
    maydin
    wrote on 18 Jul 2018, 20:34 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 18 Jul 2018, 20:56 last edited by
      #2

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

      M 1 Reply Last reply 18 Jul 2018, 22:56
      0
      • M mrjj
        18 Jul 2018, 20:56

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

        M Offline
        M Offline
        maydin
        wrote on 18 Jul 2018, 22:56 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()?

        M 1 Reply Last reply 18 Jul 2018, 23:33
        0
        • M maydin
          18 Jul 2018, 22:56

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 18 Jul 2018, 23:33 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 19 Jul 2018, 15:41
          1
          • M mrjj
            18 Jul 2018, 23:33

            @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 19 Jul 2018, 15:41 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.

            M 1 Reply Last reply 19 Jul 2018, 15:49
            0
            • M maydin
              19 Jul 2018, 15:41

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 19 Jul 2018, 15:49 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

              6/6

              19 Jul 2018, 15:49

              • Login

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