Results 1 to 5 of 5

Thread: QHttp of QT Assistant example

  1. #1
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question QHttp of QT Assistant example

    hi all
    i am working on MacOS X and using QT4.1 for application

    In QHttp Example of Qt Manual when we start download any .exe or .dmg from server then it takes some time span then it show the progressDialog where when basically downloading get started

    now My Question is after click the download botton and till then downloading get started what processes are taken place???

    and can we show 3-4 label text on the dialog (where the download button is placed)that would be keep on changing till then the downloading get started ???

    and if it can be done then how it can be done ????


    thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp of QT Assistant example

    Well, if you look over the sources, almost everything happens in HttpWindow::downloadFile. This slot gets called when you press the download button.

    Qt Code:
    1. void HttpWindow::downloadFile()
    2. {
    3. QUrl url(urlLineEdit->text());
    4. QFileInfo fileInfo(url.path());
    5. QString fileName = fileInfo.fileName();
    6. if (fileName.isEmpty())
    7. fileName = "index.html";
    8.  
    9. if (QFile::exists(fileName)) {
    10. if (QMessageBox::question(this, tr("HTTP"),
    11. tr("There already exists a file called %1 in "
    12. "the current directory. Overwrite?").arg(fileName),
    13. QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Cancel)
    14. == QMessageBox::Cancel)
    15. return;
    16. QFile::remove(fileName);
    17. }
    18.  
    19. file = new QFile(fileName);
    20. if (!file->open(QIODevice::WriteOnly)) {
    21. QMessageBox::information(this, tr("HTTP"),
    22. tr("Unable to save the file %1: %2.")
    23. .arg(fileName).arg(file->errorString()));
    24. delete file;
    25. file = 0;
    26. return;
    27. }
    28.  
    29. QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
    30. http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
    31.  
    32. if (!url.userName().isEmpty())
    33. http->setUser(url.userName(), url.password());
    34.  
    35. httpRequestAborted = false;
    36. httpGetId = http->get(url.path(), file);
    37.  
    38. progressDialog->setWindowTitle(tr("HTTP"));
    39. progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
    40. downloadButton->setEnabled(false);
    41. }
    To copy to clipboard, switch view to plain text mode 

    It first does some decent verifications(if the file already exists locally, etc).

    The delay you mentioned probably comes from QHttp. It is the time it takes QHttp to connect to server and starting downloading the file. I guess that is OK.

    and can we show 3-4 label text on the dialog (where the download button is placed)that would be keep on changing till then the downloading get started ???
    Well, you can, but I guess you won't have time to show much things in there.

    Regards

  3. #3
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Question Re: QHttp of QT Assistant example

    firstly thanks for replying
    i know well what is happening in this process but if i wanna show some changing label text , like for two second label text on dialog is one and for another 3,4,5 seconds the label text should be changed, in that time spam which is taken by http

    if it is possible the please do write some example code for it???

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QHttp of QT Assistant example

    I think you can see when the download actually starts if you hook to the dataReadProgress signal.
    When you first receive this signal then it means that the first chunk has been donwloaded.

    To display some text I suggest using QTimer.
    I cannot give you an example since I am not sure it would work. Just a draft, maybe:
    Qt Code:
    1. in constructor:
    2. mTimer = new QTimer();
    3. mTimer->setInterval(1000); //1 second;
    4. mStringList << "message1";
    5. mStringList << "message2";
    6. mStringList << "message3";
    7. mStringList << "message4";
    8. connect(mTimer, SIGNAL(timeout()), this, SLOT(cycleMessages()));
    9. connect(downloadButton, SIGNAL(clicked()), mTimer, SLOT(start())); //start the timer when download is pressed
    10.  
    11. this is the timer slot:
    12. void HttpWindow::cycleMessages()
    13. {
    14. int msgIndex = mStringList.indexOf(firstLabel->text());
    15. if(msgIndex < 0 )
    16. msgIndex = 0;
    17. else
    18. msgIndex++;
    19. if(msgIndex >= mStringList.count())
    20. msgIndex = 0;
    21.  
    22. firstLabel->setText(mStringList.at(msgIndex);
    23. }
    24.  
    25. void HttpWindow::updateDataReadProgress(int bytesRead, int totalBytes)
    26. {
    27. ...
    28. mTimer->stop();
    29. }
    To copy to clipboard, switch view to plain text mode 

    So there you will have a label that just displays those 4 messages in a cycle. The message is switched every second.
    When it reaches the end of the list, it starts again from the beginning.

    mTimer is a QTimer* member.
    mStringList is a QStringList member.
    firstLabel is a QLabel* member.



    Make sure to delete the QTimer in the destructor.

    Regards

  5. The following user says thank you to marcel for this useful post:

    thomasjoy (3rd August 2007)

  6. #5
    Join Date
    Mar 2007
    Posts
    69
    Thanks
    14
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X

    Default Re: QHttp of QT Assistant example

    but do tell me it is not be connected as on the download button Http example had put the another signal that is downloadFile() which get started as we click it
    so on one button two slot how we can put??

Similar Threads

  1. From QHttp to QHttp over SSL
    By Nyphel in forum Newbie
    Replies: 1
    Last Post: 3rd July 2007, 10:41
  2. Qt Assistant path
    By aamer4yu in forum Installation and Deployment
    Replies: 3
    Last Post: 1st February 2007, 14:23
  3. Replies: 1
    Last Post: 18th July 2006, 12:06
  4. Qt assistant under linux
    By jochen_r in forum Newbie
    Replies: 8
    Last Post: 10th January 2006, 08:39

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.