Results 1 to 2 of 2

Thread: QNetworkAccessManager & QML Progress

  1. #1
    Join Date
    May 2011
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QNetworkAccessManager & QML Progress

    I am trying to use QNetworkAccessManger to upload a file and show progress. I have the upload portion working excellently. I cannot seem to get the Progress portion working.

    I have a QML ProgressBar on one screen of my mobile app. I tried setting up a Signal like so:

    Qt Code:
    1. QNetworkAccessManager *manager = new QNetworkAccessManager(this); //using qnetwork access manager for post data
    2. QObject *root = engine.rootObjects().first();
    3. root->setProperty("networkAccess",manager);
    4.  
    5. manager->post(req,datas); //send all data
    6. connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(erroron_filesend(QNetworkReply*)));
    7. connect(manager, SIGNAL(uploadProgress(qint64 uplPart, qint64 uplTotal)), SLOT(progressChanged(qint64 uplPart, qint64 uplTotal)));
    To copy to clipboard, switch view to plain text mode 

    In my main.qml, tried to declare a local variant to hold a reference to the Manager:

    Qt Code:
    1. property variant networkAccess
    To copy to clipboard, switch view to plain text mode 

    Then in the QML with the ProgressBar I did this:

    Qt Code:
    1. ProgressBar {
    2. id: fileUplProgress
    3. visible: false
    4. anchors.top: busyLabel.bottom
    5. anchors.topMargin: Funcs.psize(10,parent.height)
    6. anchors.horizontalCenter: parent.horizontalCenter
    7. width: Funcs.psize(50,parent.width)
    8. height: Funcs.psize(5,parent.hight)
    9.  
    10. minimumValue: 0.0
    11. maximumValue: 100.0
    12. }
    13. Connections {
    14. target: appWin.networkAccess
    15. onProgressChanged: {
    16. fileUplProgress.value = 100*uplTotal/uplPart;
    17. console.log(qsTr("Progress %1").arg(100*uplTotal/uplPart);
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    First error I get is with declaring the variant for the Manager in the qml. I have other variants that hold strings passed from C++, so I know it works.

    In short, what is the best way to upload a file in C++ and get the progress in my QML page?

    --Sam

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkAccessManager & QML Progress

    You QML Code looks like you have an object that is exposed to QML as "appWin" through the setContextProperty mechanism.
    And it has a property of a QObject type, with a signal processChanged() which has arguments named "uplTotal" and "uplPart".

    Can you confirm that?
    Maybe even post the relevant code?

    No idea why you need that variant property though, something unrelated to this?

    Cheers,
    _

Similar Threads

  1. How to use progress bar
    By bijay in forum Newbie
    Replies: 1
    Last Post: 28th March 2012, 10:44
  2. QNetworkAccessManager and multiple progress bars
    By bigjoeystud in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2011, 03:19
  3. How to use progress bar
    By Ashwani in forum Newbie
    Replies: 6
    Last Post: 10th September 2010, 15:19
  4. Replies: 4
    Last Post: 11th March 2008, 11:44
  5. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 15:11

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.