MdEditor: close the temporary file explicitly after writing

This commit is contained in:
Le Tan 2018-10-08 20:40:45 +08:00
parent 61909c2c5d
commit dc9c9f6bbd
4 changed files with 10 additions and 4 deletions

View File

@ -17,7 +17,8 @@ void VDownloader::handleDownloadFinished(QNetworkReply *reply)
data = reply->readAll(); data = reply->readAll();
reply->deleteLater(); reply->deleteLater();
emit downloadFinished(data, reply->url().toString()); // The url() of the reply may be redirected and different from that of the request.
emit downloadFinished(data, reply->request().url().toString());
} }
static QNetworkRequest networkRequest(const QUrl &p_url) static QNetworkRequest networkRequest(const QUrl &p_url)

View File

@ -18,6 +18,7 @@ public:
static QByteArray downloadSync(const QUrl &p_url); static QByteArray downloadSync(const QUrl &p_url);
signals: signals:
// Url is the original url of the request.
void downloadFinished(const QByteArray &data, const QString &url); void downloadFinished(const QByteArray &data, const QString &url);
private slots: private slots:

View File

@ -1719,6 +1719,7 @@ void VMdEditor::exportGraphAndCopy(const QString &p_lang,
} }
if (out.isEmpty() || m_exportTempFile->write(out) == -1) { if (out.isEmpty() || m_exportTempFile->write(out) == -1) {
m_exportTempFile->close();
VUtils::showMessage(QMessageBox::Warning, VUtils::showMessage(QMessageBox::Warning,
tr("Warning"), tr("Warning"),
tr("Fail to export graph."), tr("Fail to export graph."),
@ -1727,8 +1728,11 @@ void VMdEditor::exportGraphAndCopy(const QString &p_lang,
QMessageBox::Ok, QMessageBox::Ok,
this); this);
} else { } else {
m_exportTempFile->close();
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->clear(); clipboard->clear();
QImage img; QImage img;
img.loadFromData(out, p_format.toLocal8Bit().data()); img.loadFromData(out, p_format.toLocal8Bit().data());
if (!img.isNull()) { if (!img.isNull()) {
@ -1741,8 +1745,6 @@ void VMdEditor::exportGraphAndCopy(const QString &p_lang,
emit m_object->statusMessage(tr("Fail to read exported image: %1").arg(filePath)); emit m_object->statusMessage(tr("Fail to read exported image: %1").arg(filePath));
} }
} }
m_exportTempFile->close();
} }
void VMdEditor::parseAndPaste() void VMdEditor::parseAndPaste()
@ -2064,6 +2066,9 @@ void VMdEditor::replaceTextWithLocalImages(QString &p_text)
if (tmpFile->open() && tmpFile->write(data) > -1) { if (tmpFile->open() && tmpFile->write(data) > -1) {
srcImagePath = tmpFile->fileName(); srcImagePath = tmpFile->fileName();
} }
// Need to close it explicitly to flush cache of small file.
tmpFile->close();
} }
} }

View File

@ -59,7 +59,6 @@ void VPreviewManager::imageDownloaded(const QByteArray &p_data, const QString &p
QPixmap image; QPixmap image;
image.loadFromData(p_data); image.loadFromData(p_data);
if (!image.isNull()) { if (!image.isNull()) {
m_editor->addImage(name, image); m_editor->addImage(name, image);
emit requestUpdateImageLinks(); emit requestUpdateImageLinks();