×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    2

    Smile Read File Using QNetworkAccessManager

    hi all, i'd like to insert in my application the possibility to read txt file from server. I've read that i can make this using class QNetwrkAccessManager, but i don't understand how can i retrive file read.
    could you help me? thanks.
    Last edited by Alexiuscrow; 2012-07-25 at 18:30.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,144

    Re: Read File Using QNetworkAccessManager

    S suppose you could do Normal HTTP GET operation.

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Read File Using QNetworkAccessManager

    Hello,

    You can read a file using QNetworkAccessManager like following:

    Code:
    //in private section of your class .h
    QNetworkAccessManager* manager;
    QNetworkReply* reply
    
    //in the cpp
    void ClassName::readFile()
    {
        manager = new QNetworkAccessManager(this);
    
        reply = manager->get(QNetworkRequest("http://url/to/file"));
    
        QObject::connect(reply, SIGNAL(finished()), this, SLOT(finished()));
    }
    
    void ClassName::finished()
    {
        QByteArray fileData = reply->readAll();
        //Do something with fileData
    }
    Br,
    Villep

  4. #4
    Registered User
    Join Date
    Jul 2012
    Posts
    2

    Re: Read File Using QNetworkAccessManager

    thx. but "QNetworkAccessManager: No such file or directory"

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Read File Using QNetworkAccessManager

    Try both

    Code:
    #include <QtNetwork/QNetworkAccessManager>
    or 
    #include <QNetworkAccessManager>
    also in .pro you should have

    Code:
    QT += network

Similar Threads

  1. QNetworkAccessManager post image file
    By hclemson in forum Qt
    Replies: 7
    Last Post: 2011-07-01, 11:34
  2. Replies: 1
    Last Post: 2010-06-22, 20:52
  3. Replies: 4
    Last Post: 2010-05-19, 14:31
  4. Replies: 2
    Last Post: 2010-03-23, 08:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •