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. [Solved] What are the odds that a QTimer or an event loop is being stopped?

[Solved] What are the odds that a QTimer or an event loop is being stopped?

Scheduled Pinned Locked Moved General and Desktop
qtimerevent loop
10 Posts 3 Posters 4.4k 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.
  • K Offline
    K Offline
    koahnig
    wrote on 24 Jun 2015, 08:39 last edited by koahnig 7 Aug 2015, 06:48
    #1

    I have an application which shall run basically 24/7. It has a timer firing every 5 seconds for some activity. This activity includes some screen output.

    The application is establishing TCP/IP connection to somewhere outside. Eventually these connection break down and have to be reconnected.

    The application is not new and some problems I had seen before. However, it was merely after a week or weeks. Now I am running more TCP sockets in parallel and the problem is actually coming within half a day. And it is showing messages of reconnection for those TCP/IP socket.

    However, I do see a reason why the timer is not triggered anymore.

    Any suggestions?

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 24 Jun 2015, 11:31 last edited by
      #2

      Hi,
      Without code it's almost impossible to help, but still a Timer will never stop working. Are you sure you don't kill/hang your eventLoop Handler? Do you reinitialize your timer in a slot?
      What type of timer do you use? Just a normal Timer that runs and runs and expires every 5 secs or do you use a SingleShot timer?
      In what tread do you run your TCP/IP connections? Is that thread still running? When it's in the Mainthread and your GUI hangs (e.g. a warning message with modal view) the events of all other objects is stalled.
      But again, without code, no idea what could go wrong!

      Greetz, Jeroen

      K 1 Reply Last reply 24 Jun 2015, 12:49
      0
      • J Jeroentjehome
        24 Jun 2015, 11:31

        Hi,
        Without code it's almost impossible to help, but still a Timer will never stop working. Are you sure you don't kill/hang your eventLoop Handler? Do you reinitialize your timer in a slot?
        What type of timer do you use? Just a normal Timer that runs and runs and expires every 5 secs or do you use a SingleShot timer?
        In what tread do you run your TCP/IP connections? Is that thread still running? When it's in the Mainthread and your GUI hangs (e.g. a warning message with modal view) the events of all other objects is stalled.
        But again, without code, no idea what could go wrong!

        K Offline
        K Offline
        koahnig
        wrote on 24 Jun 2015, 12:49 last edited by koahnig
        #3

        @Jeroentjehome

        Thanks for reply. You are right that without code it is always a problem. However, the code would be too complex to comprehend.

        Sometimes it is helpful to describe that someone else can get an idea what you are doing. Even "general" answers may provide the spark for better grabbig the problem.

        @Jeroentjehome said:

        Without code it's almost impossible to help, but still a Timer will never stop working.

        That reflects my understanding.

        Are you sure you don't kill/hang your eventLoop Handler? Do you reinitialize your timer in a slot?

        Nope.

        What type of timer do you use? Just a normal Timer that runs and runs and expires every 5 secs or do you use a SingleShot timer?

        QTimer and it runs continuously, at least it should.

        In what tread do you run your TCP/IP connections? Is that thread still running? When it's in the Mainthread and your GUI hangs (e.g. a warning message with modal view) the events of all other objects is stalled.

        Only the main thread. no additional explicit threading done.

        I have checked for a "wild" loop, but the task manager does not show CPU consumption. It looks idle to me. I guess all connection are stopped in the mean time. The timer loop shall actually ensure that those connections are re-established.
        I am using waitforconnection() for TCP socket, but I limit those to 30 seconds.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 24 Jun 2015, 22:18 last edited by
          #4

          Hi,

          What OS are you running ?

          Are you re-using the same sockets or creating new ones ?

          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 25 Jun 2015, 05:48
          0
          • S SGaist
            24 Jun 2015, 22:18

            Hi,

            What OS are you running ?

            Are you re-using the same sockets or creating new ones ?

            K Offline
            K Offline
            koahnig
            wrote on 25 Jun 2015, 05:48 last edited by
            #5

            @SGaist
            OS is windows 7 64 bit. Qt 5.3.1 MinGW 32 bit to be precise.
            I see aparently the same issue on Windows 2008 server editions.

            When I decide that a socket has to be reconnected because no info is coming in, I am deleting this socket and set up a new one.
            This is a direct delete in the wrapper. Since no crashes are occurring it seems to be possible. So there is no deleteLater and an overlap for whatever reason.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jeroentjehome
              wrote on 25 Jun 2015, 06:28 last edited by
              #6

              Using deleteLater would be better if you use connections to the deleted socket. That will make sure your event queue is empty.
              Are there delays in your socket setup? Do you restart the timer there or do you just keep on going? Do you wait for a system response when you delete or start a socket?
              Does your GUI still run when your program halts?

              Greetz, Jeroen

              K 1 Reply Last reply 25 Jun 2015, 08:16
              0
              • J Jeroentjehome
                25 Jun 2015, 06:28

                Using deleteLater would be better if you use connections to the deleted socket. That will make sure your event queue is empty.
                Are there delays in your socket setup? Do you restart the timer there or do you just keep on going? Do you wait for a system response when you delete or start a socket?
                Does your GUI still run when your program halts?

                K Offline
                K Offline
                koahnig
                wrote on 25 Jun 2015, 08:16 last edited by
                #7

                @Jeroentjehome
                I have one main timer which is not restarted, but not stopped either. This timer is triggering the screen output. That is also the timer in question, because at a certain point is not fired anymore.

                Basically each QTcpSocket is hosted in a class which hjas independent QTimer as a watch dog. Those timers are not restarted.

                Sometimes there are socket delays. At least that is my assumption since there are several starts in a row.

                The application in question does not have a GUI. However, I am using the same stuff in an application with GUI. The GUI eventually blocks and no way to get it back. Assume that I am looking for the same issue here.

                I have noted this morning that the main timer, which shall be fired every 5 seconds, is varying quite a lot. Have seen values between 1 up to 20 seconds. The event loop must busy for something, respectively it is waiting for something.

                The QTcpSocket is an instance in my wrapper class. The direct delete kills the socket and all connections at once. There should be no additional signals coming in and messing up the decoding I am doing. As indicated above, the delete does not crash anything, which is to be expected since the pointer is not owned in one of the other classes.

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 25 Jun 2015, 22:07 last edited by
                  #8

                  What OS is it ?

                  Do you have a WiFi adapter on the machine ?

                  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 26 Jun 2015, 10:42
                  0
                  • S SGaist
                    25 Jun 2015, 22:07

                    What OS is it ?

                    Do you have a WiFi adapter on the machine ?

                    K Offline
                    K Offline
                    koahnig
                    wrote on 26 Jun 2015, 10:42 last edited by
                    #9

                    @SGaist
                    OS is win 7 64 bit primarily.
                    No WIFI used.

                    I have changed the code yesterday. I found, actually I knew its presence, a waitForReadyRead(-1) in the code, when I requested more bytes to read than actually available. Certainly that would explain immediately the behaviour. However, this was only possible to enter when the number of bytesAvailable() would report the wrong number of bytes. I doubt that bytesAvailable would report more bytes than actually available. Anyway I took away those odds.

                    Vote the answer(s) that helped you to solve your issue(s)

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      koahnig
                      wrote on 8 Jul 2015, 06:47 last edited by
                      #10

                      I have found the problem. It was a blocking ftp download which did not finish because of broken communication. Pushing the download to a separate thread unveiled the problem respectively made it tracable.

                      Vote the answer(s) that helped you to solve your issue(s)

                      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