Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. How to call timerEvent(QTimerEvent *event) defined in separate class through startTimer(1000) function defined in another slot in that class only?

How to call timerEvent(QTimerEvent *event) defined in separate class through startTimer(1000) function defined in another slot in that class only?

Scheduled Pinned Locked Moved Unsolved India
6 Posts 2 Posters 1.7k 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.
  • S Offline
    S Offline
    SHUBHAM SINGH RAO
    wrote on 13 Dec 2018, 05:05 last edited by SHUBHAM SINGH RAO
    #1

    hi everyone!
    Aim : To interface modem with my qt programme by making a separate gprs_modem class

    Methodology used: I have defined a separate class 'gprs_modem' , with all member functions defined in that class.
    I am calling (and using) the members functions of that class in mainwindow by making object of that class.

    Challenge: One of the member function defined in gprs_modem class is
    *void gprs_modem::timerEvent(QTimerEvent event)

    Steps which my programme supposed to execute :

    1. I want to call function1 (of gprs_modem class) through a pushbutton slot in mainwindow
    2. function1 will startTimer(1000)
    3. function1 should call timerEvent function of modem_class after each second

    I am attaching my code alongwith for your kind reference.

    // mainWindow.cpp

    gprs_modem object1; //make object of gprs_modem class

    void MainWindow::on_pushButton_clicked()
    { //calling function1 of gprs_modem Class so as to initiate timer

      object1.function1();       
    

    }

    //gprs_modem class ( my separate class )

    void gprs_modem::function1()
    {
    startTimer(1000);
    //now it should call QTimerEvent class defined below
    }

    void gprs_modem::timerEvent(QTimerEvent *event)
    {
    // do something
    }

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Maaz Momin
      wrote on 13 Dec 2018, 05:31 last edited by
      #2

      You can install event filter of gprs_modem class on MainWindow and then check inside MainWindow::eventFilter()

      Code::
      object1->installEventFilter(this); // Wherever you instantiate gprs_modem class

      and then in :

      MainWindow::eventFilter(QObject *watched, QEvent *event)
      {
      if(watched == object1 && event-type() == QEvent::Timer)
      {
      // You can then either convert event to QTimerEvent or do your stuff directly.
      }
      }

      S 2 Replies Last reply 13 Dec 2018, 06:21
      0
      • M Maaz Momin
        13 Dec 2018, 05:31

        You can install event filter of gprs_modem class on MainWindow and then check inside MainWindow::eventFilter()

        Code::
        object1->installEventFilter(this); // Wherever you instantiate gprs_modem class

        and then in :

        MainWindow::eventFilter(QObject *watched, QEvent *event)
        {
        if(watched == object1 && event-type() == QEvent::Timer)
        {
        // You can then either convert event to QTimerEvent or do your stuff directly.
        }
        }

        S Offline
        S Offline
        SHUBHAM SINGH RAO
        wrote on 13 Dec 2018, 06:21 last edited by
        #3

        @Maaz-Momin ok...let me try it!

        1 Reply Last reply
        0
        • M Maaz Momin
          13 Dec 2018, 05:31

          You can install event filter of gprs_modem class on MainWindow and then check inside MainWindow::eventFilter()

          Code::
          object1->installEventFilter(this); // Wherever you instantiate gprs_modem class

          and then in :

          MainWindow::eventFilter(QObject *watched, QEvent *event)
          {
          if(watched == object1 && event-type() == QEvent::Timer)
          {
          // You can then either convert event to QTimerEvent or do your stuff directly.
          }
          }

          S Offline
          S Offline
          SHUBHAM SINGH RAO
          wrote on 18 Dec 2018, 05:27 last edited by
          #4

          @Maaz-Momin i have posted my updated query, kindly have a look at it!

          M 1 Reply Last reply 18 Dec 2018, 08:19
          0
          • S SHUBHAM SINGH RAO
            18 Dec 2018, 05:27

            @Maaz-Momin i have posted my updated query, kindly have a look at it!

            M Offline
            M Offline
            Maaz Momin
            wrote on 18 Dec 2018, 08:19 last edited by
            #5

            @SHUBHAM-SINGH-RAO What's your updated query?

            S 1 Reply Last reply 18 Dec 2018, 08:23
            0
            • M Maaz Momin
              18 Dec 2018, 08:19

              @SHUBHAM-SINGH-RAO What's your updated query?

              S Offline
              S Offline
              SHUBHAM SINGH RAO
              wrote on 18 Dec 2018, 08:23 last edited by
              #6

              @Maaz-Momin https://forum.qt.io/topic/97741/query-related-to-waiting-timer-class

              1 Reply Last reply
              0

              6/6

              18 Dec 2018, 08:23

              • Login

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