Results 1 to 4 of 4

Thread: Qtimer is not working....

  1. #1
    Join Date
    May 2012
    Posts
    33
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Qtimer is not working....

    im writing some code to send request to google... so i need to place some delay between my request... i thought that the below code will work.. but nothing happen... do u know whats the problem?



    // some code untill here

    qDebug() << "Wait three Second...!";

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(fake()));
    timer->start(3000);

    myHttp.request(myRequestHeader);

    connect(&myHttp,SIGNAL(responseHeaderReceived(QHtt pResponseHeader)),
    this,SLOT(showResponseHeader(QHttpResponseHeader)) );


    the fake() is a fake slot just for calling when the timer timed out...
    and doing sthing like this
    int a;
    a++;


    whats the problem here?

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qtimer is not working....

    Maybe better make list of requests and on timer timeout exec request from list

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qtimer is not working....

    whats the problem here?
    QTimer does not introduce a delay, it schedules an event for later. You schedule a timer to fire in three seconds (or the first time the Qt event loop is reached after that time). You then schedule an HTTP request (using the obsolete and deprecated QHttp class) that will also happen later. Both events are scheduled immediately, and both events will be candidates to run when the event loop is next reached. Usually this will happen in less than three seconds so the HTTP request will happen (at least start) before the timer fires.

    If the delay and request is a one-off then you could queue the HTTP request (using QNetworkRequest and QNetworkAccessManager) in the timer slot. If you have a series of requests to send a three second intervals then Jonny174 has a good suggestion.

  4. #4
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: Qtimer is not working....

    i think your timer section code have no error...
    Last edited by Ali Reza; 21st June 2012 at 08:21.
    Life is about making the right decisions and moving on.

Similar Threads

  1. QTimer or something else
    By .:saeed:. in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2011, 07:47
  2. Use a QTimer in a Qt-non-GUI app.
    By hakermania in forum Newbie
    Replies: 11
    Last Post: 29th August 2010, 10:36
  3. QTimer - Why this is not working?
    By prasenjit in forum Newbie
    Replies: 2
    Last Post: 17th December 2009, 16:37
  4. Use of QTimer
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 4
    Last Post: 7th August 2009, 13:52
  5. QTimer
    By link7 in forum Newbie
    Replies: 4
    Last Post: 2nd June 2009, 08:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.