Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C++ by anon ( 14 years ago )
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtCore>

#include <QtNetwork/QtNetwork>
#include <QDebug>
#include <QFile>


#include <QtGui>

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);

    QFile file;

    QString link;
    QLineEdit* edit;
    QPushButton* btn;
    QGridLayout* layout;
    QNetworkAccessManager* networkManager() { return pNetManager; }

    ~MainWindow();

private:
    QNetworkAccessManager *pNetManager;

public slots:
    void slotReadyRead();
    void slotError(QNetworkReply::NetworkError);
    void slotFinished();
};

#endif // MAINWINDOW_H




#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    pNetManager = new QNetworkAccessManager(this);

    QNetworkRequest request;
    request.setUrl(QUrl("http://www.yoba.ru/yoba.avi"));
    request.setRawHeader("Accept-Encoding", "gzip,deflate");
    QNetworkReply *reply = pNetManager->get(request);
    connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
                this, SLOT(slotError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(finished()), this, SLOT(slotFinished()));

    layout = new QGridLayout;
    btn=new QPushButton("download");      
    edit = new QLineEdit("adress");
    layout->addWidget(edit,0,0);
    layout->addWidget(btn,1,0);
    QWidget *widget = new QWidget;
    widget->setLayout(layout);
    setCentralWidget(widget);
    file.setFileName("lost.avi");
    file.open(QIODevice::WriteOnly);

}

void MainWindow::slotReadyRead()
{
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    file.write(reply->readAll());
}
void MainWindow::slotFinished()
{   
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    file.close();
    reply->deleteLater();
}
void MainWindow::slotError(QNetworkReply::NetworkError error)
{

}

MainWindow::~MainWindow()
{

}




#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
}

 

Revise this Paste

Parent: 22546
Children: 22705 22706 22788
Your Name: Code Language: