从QWebView类中下载图片
来源:互联网 发布:淘宝网的网址域名 编辑:程序博客网 时间:2024/05/17 05:50
forked from :http://www.qtcentre.org/threads/41997-Qwebview-Copy-Text-And-Save-Image
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
Qt Code:
private slots: void downloadRequested(const QNetworkRequest &); //used for save image void downloadingIssueFinished(); //used for save image void keyPressEvent(QKeyEvent *e); //used for crtl-c
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
Qt Code:
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());}
This is for the Ctrl-C Bit
Qt Code:
void frm_web::keyPressEvent(QKeyEvent *e){ if((e->key() == Qt::Key_C) && (e->modifiers().testFlag(Qt::ControlModifier))) { qApp->clipboard()->setText(ui->webView->selectedText()); }}
And to connect the signals and slots
Qt Code:
connect(ui->webView->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest)));
0 0
- 从QWebView类中下载图片
- 如何从网页中下载图片
- 使用HttpURLConnection从网络中下载图片
- [python][爬虫]从网页中下载图片
- 让QWebView支持下载文件
- 利用QWebView加载mjpg图片
- QWebView中加载本地html网页中图片加载失败的解决方法
- 从网上下载图片
- 从服务器下载图片
- QWebView
- QWebView
- 不下载直接从TMEMORYSTREAM中读取图片.
- php - 如何从php代码中下载图片
- 利用jsoup 如何从网页中下载图片
- python3.2从网络中下载一张图片
- 从网页中下载图片遇到的坑
- Android中从网上下载一张图片显示进度并显示下载好的图片
- 将QwebView转成图片打印及保存
- 究竟想要怎样
- 使用BackgroundWorker组件
- java调用淘宝API实例
- mac 系统开发android 真机调试找不到设备的问题
- [Openstack-keystone] Expecting an auth URL via either --os-auth-url or env[OS_AUTH_URL]
- 从QWebView类中下载图片
- 手势和UI控件之间冲突的解决方法(比如UITapGesture和UIButton冲突,UIPanGesture和UISlider冲突)
- hdu 1081 (dp_区间dp)
- 程序员如何像写代码一样找女朋友
- POJ-2421 最小生成树 算法复习计划
- 使用fedora 20
- Apache2.4.3编译移植
- POJ1144-Network(割顶模板题)
- hdu-4857-逃生-拓扑排序