Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Timer instance connection delete

    General and Desktop
    timer instance detection
    3
    4
    974
    Loading More Posts
    • 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.
    • McLion
      McLion last edited by McLion

      Hi

      I have the following to have a cert periodically updated:

      QTimer *SSLupdateTimer = new QTimer(this);
      connect(SSLupdateTimer, SIGNAL(timeout()), this, SLOT(UpdateSSLcertificate()));
      SSLupdateTimer->setInterval(CERT_UPDATE_INTERVAL);
      SSLupdateTimer->start();
      

      Usually this is called once. If this is called again, this will create a second timer, right? And it will also create another connection.

      How do I best catch this? How do I detect if there already is an instance and then kill it as well as the connection before creating a new one?

      ... or am I somehow wrong?
      Thanks

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Why not keep that timer as a private member of the class, null_ptr by default and check whether it's initialized when calling the function that contains that code ?

        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 Reply Quote 1
        • jsulm
          jsulm Lifetime Qt Champion last edited by

          Why do you create the timer instance on the heap?
          And if you want to do it like this, then put the pointer in your class and initialize the pointer with 0.
          Then each time your code is executed you check whether the pointer is null, if it is then you execute your code if not you do nothing.
          Do you delete the timer instance somewhere?

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

          1 Reply Last reply Reply Quote 1
          • McLion
            McLion last edited by

            Thank you guys.
            I see that it was wrong to create it on the heap.
            I moved the creation and made it a private member of the class. When called, I check it's initialization and proceed accordingly.
            Works a treat.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post