Thanks arturo182.
That worked great. And im greatfull for you putting me in the right direction for the image downloading.
Below is the full code for anyone looking at this thread. I hope it helps someone as this task has wasted me 2 days
Header File
private slots:
void downloadRequested(const QNetworkRequest &); //used for save image
void downloadingIssueFinished(); //used for save image
void keyPressEvent
(QKeyEvent *e
);
//used for crtl-c
private slots:
void downloadRequested(const QNetworkRequest &); //used for save image
void downloadingIssueFinished(); //used for save image
void keyPressEvent(QKeyEvent *e); //used for crtl-c
To copy to clipboard, switch view to plain text mode
cpp file - the below code was taken from http://www.linuxjournal.com/magazine...op-application
this code is for the same image bit of the fix
void frm_web::downloadRequested(
const QNetworkRequest &request)
{
// First prompted with a file dialog to make sure
// they want the file and to select a download
// location and name.
QFileInfo(request.
url().
toString()).
fileName();
tr("Save File"),
defaultFileName);
if (fileName.isEmpty())
return;
// Construct a new request that stores the
// file name that should be used when the
// download is complete
QNetworkRequest newRequest = request;
newRequest.setAttribute(QNetworkRequest::User,
fileName);
// Ask the network manager to download
// the file and connect to the progress
// and finished signals.
QNetworkAccessManager *networkManager =
ui->webView->page()->networkAccessManager();
QNetworkReply *reply =
networkManager->get(newRequest);
//connect(
//reply, SIGNAL(downloadProgress(qint64, qint64)),
//this, SLOT(downloadProgress(qint64, qint64)));
connect(reply, SIGNAL(finished()),
this, SLOT(downloadingIssueFinished()));
}
void frm_web::downloadingIssueFinished()
{
QNetworkReply *reply = ((QNetworkReply*)sender());
QNetworkRequest request = reply->request();
request.attribute(QNetworkRequest::User);
if (file.
open(QFile::ReadWrite)) file.write(reply->readAll());
}
void frm_web::downloadRequested(
const QNetworkRequest &request)
{
// First prompted with a file dialog to make sure
// they want the file and to select a download
// location and name.
QString defaultFileName =
QFileInfo(request.url().toString()).fileName();
QString fileName =
QFileDialog::getSaveFileName(this,
tr("Save File"),
defaultFileName);
if (fileName.isEmpty())
return;
// Construct a new request that stores the
// file name that should be used when the
// download is complete
QNetworkRequest newRequest = request;
newRequest.setAttribute(QNetworkRequest::User,
fileName);
// Ask the network manager to download
// the file and connect to the progress
// and finished signals.
QNetworkAccessManager *networkManager =
ui->webView->page()->networkAccessManager();
QNetworkReply *reply =
networkManager->get(newRequest);
//connect(
//reply, SIGNAL(downloadProgress(qint64, qint64)),
//this, SLOT(downloadProgress(qint64, qint64)));
connect(reply, SIGNAL(finished()),
this, SLOT(downloadingIssueFinished()));
}
void frm_web::downloadingIssueFinished()
{
QNetworkReply *reply = ((QNetworkReply*)sender());
QNetworkRequest request = reply->request();
QVariant v =
request.attribute(QNetworkRequest::User);
QString fileName = v.toString();
QFile file(fileName);
if (file.open(QFile::ReadWrite))
file.write(reply->readAll());
}
To copy to clipboard, switch view to plain text mode
This is for the Ctrl-C Bit
{
if((e->key() == Qt::Key_C) && (e->modifiers().testFlag(Qt::ControlModifier))) {
qApp->clipboard()->setText(ui->webView->selectedText());
}
}
void frm_web::keyPressEvent(QKeyEvent *e)
{
if((e->key() == Qt::Key_C) && (e->modifiers().testFlag(Qt::ControlModifier))) {
qApp->clipboard()->setText(ui->webView->selectedText());
}
}
To copy to clipboard, switch view to plain text mode
And to connect the signals and slots
connect(ui->webView->page(),
SIGNAL(downloadRequested(QNetworkRequest)),
this, SLOT(downloadRequested(QNetworkRequest)));
connect(ui->webView->page(),
SIGNAL(downloadRequested(QNetworkRequest)),
this, SLOT(downloadRequested(QNetworkRequest)));
To copy to clipboard, switch view to plain text mode
Bookmarks