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. Timer instance connection delete
QtWS25 Last Chance

Timer instance connection delete

Scheduled Pinned Locked Moved Solved General and Desktop
timer instancedetection
4 Posts 3 Posters 1.3k 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
    McLion
    wrote on 4 Dec 2015, 09:58 last edited by McLion 12 Apr 2015, 09:58
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Dec 2015, 10:02 last edited by
      #2

      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
      1
      • J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 4 Dec 2015, 10:02 last edited by
        #3

        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
        1
        • M Offline
          M Offline
          McLion
          wrote on 4 Dec 2015, 10:28 last edited by
          #4

          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
          0

          1/4

          4 Dec 2015, 09:58

          • Login

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