Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: QNetworkRequest atribute

  1. #21
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QNetworkRequest atribute

    Quote Originally Posted by unit View Post
    QObject::setProperty() is good solution.
    Qt Code:
    1. QNetworkRequest request;
    2. request.setProperty("a123","b456");
    3. ...
    4. accessManager->get(request);
    5. ....
    6. ...._finished(QNetworkReply *reply)
    7. {
    8. qDebug() << "test:" << reply->property("a123");
    9. ...
    To copy to clipboard, switch view to plain text mode 

    reply has property, but networkrequest not:

    Qt Code:
    1. error: ‘class QNetworkRequest’ has no member named ‘setProperty’
    To copy to clipboard, switch view to plain text mode 

  2. #22
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QNetworkRequest atribute

    Read again what wysota posted:
    use QObject::setProperty() on the reply object you get when issuing a request to QNetworkAccessManager.

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

    Default Re: QNetworkRequest atribute

    If you INSIST on using attributes, you can always do this:
    Qt Code:
    1. class MyNetworkAccessManager : public QNetworkAccessManager {
    2. public:
    3. enum CustomAttribute { Attr1 = QNetworkRequest::User, Attr2 };
    4. protected:
    5. QNetworkReply * createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 ) {
    6. QNetworkReply *reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
    7. if(req.attribute(Attr1).isValid()) reply->setAttribute(Attr1, req.attribute(Attr1));
    8. if(req.attribute(Attr2).isValid()) reply->setAttribute(Attr2, req.attribute(Attr2));
    9. return reply;
    10. }
    11. };
    To copy to clipboard, switch view to plain text mode 
    ... although I see no point in doing that. Attributes are there to mean something and not to provide storage for custom data. This is what dynamic properties are for.
    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.


  4. #24
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: QNetworkRequest atribute

    For your code is:

    Qt Code:
    1. ...
    2. QNetworkRequest request;
    3. request.setUrl(QUrl(strUrl));
    4. QNetworkReply reply = accessManager->get(request);
    5. reply->setProperty("test1", strTest1);
    6. reply->setProperty("cat", strCategory);
    7. ...
    8.  
    9. ... net_finished(QNetworkReply *reply)
    10. {
    11. reply->deleteLater();
    12.  
    13. if (reply->error())
    14. return;
    15.  
    16. QString strTest1 = reply->property("test1").toString();
    17. QString strCategory = reply->property("cat").toString();
    18. QByteArray bData = reply->readAll();
    19. ...
    To copy to clipboard, switch view to plain text mode 
    Try read Qt documentation before ask stupid question.

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

    mero (12th March 2011)

Similar Threads

  1. Replies: 1
    Last Post: 12th December 2010, 16:45
  2. Replies: 0
    Last Post: 3rd August 2010, 09:07
  3. QNetworkRequest file upload -- please help
    By Runtime Technologies in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 15:55
  4. How to see the final request from QNetworkRequest
    By krippy2k in forum Qt Programming
    Replies: 13
    Last Post: 7th June 2009, 21:37
  5. Replies: 5
    Last Post: 20th January 2009, 14: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.