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. Cannot connect Qtimer ?

Cannot connect Qtimer ?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.8k 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.
  • D Offline
    D Offline
    downunderthunder
    wrote on last edited by
    #1

    Hi,
    I am trying to connect a Qtimer as follows:

    [code]
    QTimer *timer = new QTimer(this);
    unsigned short ret_val = QObject::connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->setInterval(100);
    timer->start();
    [/code]

    unfortunately the return value of connect is always "0" so false--> so connection to timer could not be established?
    what could be the problem?
    Any suggestions?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      First of all the @QObject::connect()@ function returns a @QMetaObject::Connection@ variable, so maybe the automatic type casting is to blame, but doesn't sound likely.
      Does your this class subclass from QObject?? No need to use the @QObject::@ prefix for your connect, but that too (because the connect function is static) should not be to blame.
      The only thing I can think about is that your update() function takes arguments and the timeout() signal does not provide them. Then the connection will NOT be made. Also in QtCreator in your application output window a more detailed description will be given should the connection failed to be made.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ScottR
        wrote on last edited by
        #3

        Also, I believe update() has to be a
        public slot:

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          [quote author="downunderthunder" date="1391017218"][code]
          QTimer *timer = new QTimer(this);
          unsigned short ret_val = QObject::connect(timer, SIGNAL(timeout()), this, SLOT(update()));
          timer->setInterval(100);
          timer->start();
          [/code]

          unfortunately the return value of connect is always "0" so false--> so connection to timer could not be established?[/quote]The code you posted is in the correct format, except for "unsigned short" like Jerome pointed out.

          Did you run your code? Does update() get called?

          Anyway, if the connection fails, you will get an error message in your console. What does it say?

          [quote author="ScottR" date="1391027715"]Also, I believe update() has to be a
          public slot:[/quote]No it doesn't. The slot belongs to 'this', which is allowed to access all of its own slots (including private slots).

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • D Offline
            D Offline
            downunderthunder
            wrote on last edited by
            #5

            Well many thanks to all of you.

            The hint: "update" should be "public slot" help me somehow!

            I accidently declared it as "public" but indeed its a slot.
            now this part works fine and I can move forward...

            kind regards

            dut

            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