Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QTimer in a Pushbutton QT C++.
Qt 6.12 LTS is out! See what's new in the release blog

Using QTimer in a Pushbutton QT C++.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 591 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
    mbatra
    wrote on last edited by
    #1

    Hi,

    I am working on a QWidget application. I want to use QTimer. I have created a timer and attached its TimeOut Signal to a slot in the constructor. Now I want to start the timer when the user clicks on Start pushbutton and stop the timer when the user clicks on stop pushbutton. But when I call the timer->start function in the pushbutton (in which I am calling a different function). qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."

    Is there any way to implement the above said functionality.

    Any help would be appreciated.

    JonBJ 1 Reply Last reply
    0
    • M mbatra

      Hi,

      I am working on a QWidget application. I want to use QTimer. I have created a timer and attached its TimeOut Signal to a slot in the constructor. Now I want to start the timer when the user clicks on Start pushbutton and stop the timer when the user clicks on stop pushbutton. But when I call the timer->start function in the pushbutton (in which I am calling a different function). qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."

      Is there any way to implement the above said functionality.

      Any help would be appreciated.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @mbatra said in Using QTimer in a Pushbutton QT C++.:

      qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."

      As the message, but not your explanation, tells us, you are using multiple threads. And you cannot start/stop a QTimer from a thread different from where it was created/currently lives.

      Axel SpoerlA 1 Reply Last reply
      2
      • JonBJ JonB

        @mbatra said in Using QTimer in a Pushbutton QT C++.:

        qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."

        As the message, but not your explanation, tells us, you are using multiple threads. And you cannot start/stop a QTimer from a thread different from where it was created/currently lives.

        Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by
        #3

        @JonB
        You can implement a slot (or two) in an object living the the timer‘s thread, that starts/stops the timer. That slot can be invoked directly or by means of a signal connection.

        Software Engineer
        The Qt Company, Oslo

        JonBJ 1 Reply Last reply
        0
        • Axel SpoerlA Axel Spoerl

          @JonB
          You can implement a slot (or two) in an object living the the timer‘s thread, that starts/stops the timer. That slot can be invoked directly or by means of a signal connection.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Axel-Spoerl
          Hi Axel. Not sure why you are addressing me here? Is there something I have not understood, or did you intend it as a suggestion to @mbatra, the OP?

          Axel SpoerlA 1 Reply Last reply
          0
          • JonBJ JonB

            @Axel-Spoerl
            Hi Axel. Not sure why you are addressing me here? Is there something I have not understood, or did you intend it as a suggestion to @mbatra, the OP?

            Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #5

            @JonB
            Hi Jon,
            It was wrong to address you. I meant the OP….
            Sorry for the confusion!
            Cheers
            Axel

            Software Engineer
            The Qt Company, Oslo

            1 Reply Last reply
            1

            • Login

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