Results 1 to 8 of 8

Thread: Help me qtime in qt?

  1. #1
    Join Date
    Jun 2011
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Help me qtime in qt?

    I'm sorry, my level language not good, i'm vietnamese. And i used google translate.
    Current time is me try to write a program, it will allow connection to a website, but I want to time limit connection to that website. If that is not in 5s received data return the program will show message box "not conncect website".
    not know not start from where. Help me.

    Tamnv110. from Viet Nam.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me qtime in qt?

    QNetworkAccessManager, QTimer, signals and slots.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Help me qtime in qt?

    Thank you!
    Can I use signal timeout in Qtimer and slot finished in QNetworkAccessManager ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me qtime in qt?

    Yes, you can.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2011
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Help me qtime in qt?

    hmmm! Dear wysota!
    I not found signals and slots appropriate.
    can you specify more for me?
    Current, I have a function connect to URL:
    Qt Code:
    1. QString KiemTraKetNoi::KTTruyenDuLieu(QString &str)
    2. {
    3. QNetworkAccessManager manager;
    4. QNetworkReply *reply=manager.get(QNetworkRequest(QUrl(str)));
    5. QEventLoop evLoop;
    6. connect(reply,SIGNAL(readyRead()),&evLoop,SLOT(quit()));
    7. connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),&evLoop,SLOT(quit()));
    8. evLoop.exec();
    9. QString strDuLieu="";
    10. qDebug()<<"kiemtraketnoi.cpp KTTruyenDuLieu Network Error"<<reply->error();
    11. if(reply->error()==0)
    12. {
    13. strDuLieu=QString::fromUtf8(reply->readAll());
    14. }
    15. else
    16. {
    17. qDebug()<<"kiemtraketnoi.cpp KTTruyenDuLieu Network Error"<<reply->error();
    18. strDuLieu="";
    19. QMessageBox msgBox;
    20. QPushButton *okButton = msgBox.addButton(QString::fromUtf8("OK"), QMessageBox::ActionRole);
    21. QPushButton *noButton = msgBox.addButton(QString::fromUtf8("No"),QMessageBox::RejectRole);
    22. QString msg = reply->errorString() + " Retry?";
    23. msgBox.setText(msg);
    24. msgBox.exec();
    25. if(msgBox.clickedButton()== (QAbstractButton*)okButton)
    26. {
    27. KTTruyenDuLieu(str);
    28. }
    29. else if(msgBox.clickedButton() == (QAbstractButton*)noButton)
    30. {
    31. msgBox.close();
    32. }
    33. }
    34. reply->deleteLater();
    35. return strDuLieu;
    36. }
    To copy to clipboard, switch view to plain text mode 

    I want to if time connect to website >5s, but application not connect to this web, application return messagebox "Not connect to webstie".
    Last edited by tamnv110; 16th June 2011 at 11:25.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me qtime in qt?

    The two signals you mentioned earlier were the correct ones to use. timeout() signal of the timer will tell you 5 seconds have passed and the finished() signal of QNetworkAccessManager or QNetworkReply will tell you the file has been downloaded (or not).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2011
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Help me qtime in qt?

    I don't understand!
    I have an idea:

    QObject::Connect(time, SIGNAL(timeout()), this,SLOT(StopConnect()));

    In StopConnect(), I try stop connecting to website, but I don't know use any func of qnetwork to stop connection.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help me qtime in qt?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    tamnv110 (16th June 2011)

Similar Threads

  1. QTime
    By dragon in forum Newbie
    Replies: 12
    Last Post: 16th February 2012, 11:40
  2. QTime to a format which I can use in a calculation
    By Gavin Harper in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2011, 00:15
  3. QTime error?
    By roxton in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2010, 23:06
  4. QTime
    By bismitapadhy in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 06:21
  5. QTime restart
    By jhowland in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2008, 21:18

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.