Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Invalid characters at starting in downloaded file
Qt 6.11 is out! See what's new in the release blog

[Solved] Invalid characters at starting in downloaded file

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi everyone,
    I am downloading a page using QNetwork classes but getting some invalid characters on the starting of the file downloaded.
    Does anyone knows why my data is getting corrupted ??
    I tried downloading http://ashish-bansal.in webpage using this and getting this as output at starting line :

    @B�<!doctype html>@

    Full Code :
    @Download::Download(QString rawURL) : QObject()
    {
    mQnam = new QNetworkAccessManager();
    mUrl = new QUrl(rawURL);
    mTempFile = new QTemporaryFile("name"); //QTemporaryFile *
    if(!mTempFile->open()){
    return;
    }
    mReq = new QNetworkRequest();
    mReq->setUrl(*mUrl);
    mDownloadReply = mQnam->get(*mReq);

    connect(mDownloadReply, &QNetworkReply::downloadProgress, this, &Download::downloadProgress);
    connect(mQnam, &QNetworkAccessManager::finished, this, &Download::downloadFinished);
    

    }

    void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
    {
    }

    void Download::downloadFinished(QNetworkReply *reply)
    {
    qDebug() << "Download Finished as whole file";
    QDataStream out(mTempFile);
    QByteArray data = mDownloadReply->readAll();
    out << data;
    tempFile->close();
    reply->deleteLater();
    }
    @

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You are using QDataStream. This is a portable serialization class which means it will add some extra info e.g. the type. The extra characters are the encoded signature of QByteArray type.
      To just store the file contents either use QTextStream or simply directly the write() method of the QTemporaryFile.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        [quote author="Chris Kawa" date="1419879651"]You are using QDataStream. This is a portable serialization class which means it will add some extra info e.g. the type. The extra characters are the encoded signature of QByteArray type.
        To just store the file contents either use QTextStream or simply directly the write() method of the QTemporaryFile.[/quote]

        Everyday I learn something new from you :)
        Thanks a lot!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved