From 203c55548f67d42387086a5432ba5cdd12f21fca Mon Sep 17 00:00:00 2001 From: liuminghang Date: Fri, 25 Jun 2021 11:02:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3bug85086?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 检测到图片为空,则不启动 Log: 与程序启动有关 Bug: https://pms.uniontech.com/zentao/bug-view-85086.html Change-Id: Icd4a7b78328e2568a239e03dd44f77fb841795ba --- src/mainwidget.cpp | 11 +++++--- src/mainwidget.h | 2 +- src/mainwindow.cpp | 4 +-- src/ocrapplication.cpp | 57 ++++++++++++++++++++++++------------------ 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index 9306b41..a3d8d79 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -286,13 +286,18 @@ void MainWidget::initShortcut() } -void MainWidget::openImage(const QString &path) +bool MainWidget::openImage(const QString &path) { + bool bRet = false; if (m_imageview) { QImage img(path); - m_imgName = path; - openImage(img, m_imgName); + if (!img.isNull()) { + m_imgName = path; + openImage(img, m_imgName); + bRet = true; + } } + return bRet; } void MainWidget::openImage(const QImage &img, const QString &name) diff --git a/src/mainwidget.h b/src/mainwidget.h index ac4d3de..5d4c5c5 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -42,7 +42,7 @@ public: //初始化快捷键 void initShortcut(); - void openImage(const QString &path); + bool openImage(const QString &path); void openImage(const QImage &img, const QString &name = ""); void loadHtml(const QString &html); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7aa92f8..ca11ed6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -48,8 +48,8 @@ MainWindow::~MainWindow() bool MainWindow::openFile(const QString &filePaths) { - m_mainWidget->openImage(filePaths); - return true; + //更改打开判断文件是否是图片文件 + return m_mainWidget->openImage(filePaths);; } bool MainWindow::openImage(const QImage &image, const QString &name) diff --git a/src/ocrapplication.cpp b/src/ocrapplication.cpp index 88454c4..8795b39 100644 --- a/src/ocrapplication.cpp +++ b/src/ocrapplication.cpp @@ -30,43 +30,50 @@ OcrApplication::OcrApplication(QObject *parent) : QObject(parent) bool OcrApplication::openFile(QString filePath) { - - qDebug() << __FUNCTION__ << __LINE__ << filePath; MainWindow *win = new MainWindow(); - win->openFile(filePath); - win->show(); - //第一次启动才居中 - if (m_loadingCount == 0) { - Dtk::Widget::moveToCenter(win); - m_loadingCount++; + //增加判断,空图片不会启动 + bool bRet = win->openFile(filePath); + if (bRet) { + win->show(); + //第一次启动才居中 + if (m_loadingCount == 0) { + Dtk::Widget::moveToCenter(win); + m_loadingCount++; + } } - return true; + + return bRet; } void OcrApplication::openImage(QImage image) { - qDebug() << __FUNCTION__ << __LINE__ << image.size(); - MainWindow *win = new MainWindow(); - win->openImage(image); - win->show(); - //第一次启动才居中 - if (m_loadingCount == 0) { - Dtk::Widget::moveToCenter(win); - m_loadingCount++; + //增加判断,空图片不会启动 + if (!image.isNull() && image.width() >= 1) { + qDebug() << __FUNCTION__ << __LINE__ << image.size(); + MainWindow *win = new MainWindow(); + win->openImage(image); + win->show(); + //第一次启动才居中 + if (m_loadingCount == 0) { + Dtk::Widget::moveToCenter(win); + m_loadingCount++; + } } } void OcrApplication::openImageAndName(QImage image, QString imageName) { - qDebug() << __FUNCTION__ << __LINE__ << image.size(); - MainWindow *win = new MainWindow(); - win->openImage(image, imageName); - win->show(); - //第一次启动才居中 - if (m_loadingCount == 0) { - Dtk::Widget::moveToCenter(win); - m_loadingCount++; + //增加判断,空图片不会启动 + if (!image.isNull() && image.width() >= 1) { + MainWindow *win = new MainWindow(); + win->openImage(image, imageName); + win->show(); + //第一次启动才居中 + if (m_loadingCount == 0) { + Dtk::Widget::moveToCenter(win); + m_loadingCount++; + } } }