fix: 解决bug85086

Description: 检测到图片为空,则不启动

Log: 与程序启动有关
Bug: https://pms.uniontech.com/zentao/bug-view-85086.html
Change-Id: Icd4a7b78328e2568a239e03dd44f77fb841795ba
This commit is contained in:
liuminghang 2021-06-25 11:02:29 +08:00
parent 902758fd49
commit 203c55548f
4 changed files with 43 additions and 31 deletions

View File

@ -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) { if (m_imageview) {
QImage img(path); QImage img(path);
m_imgName = path; if (!img.isNull()) {
openImage(img, m_imgName); m_imgName = path;
openImage(img, m_imgName);
bRet = true;
}
} }
return bRet;
} }
void MainWidget::openImage(const QImage &img, const QString &name) void MainWidget::openImage(const QImage &img, const QString &name)

View File

@ -42,7 +42,7 @@ public:
//初始化快捷键 //初始化快捷键
void initShortcut(); void initShortcut();
void openImage(const QString &path); bool openImage(const QString &path);
void openImage(const QImage &img, const QString &name = ""); void openImage(const QImage &img, const QString &name = "");
void loadHtml(const QString &html); void loadHtml(const QString &html);

View File

@ -48,8 +48,8 @@ MainWindow::~MainWindow()
bool MainWindow::openFile(const QString &filePaths) 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) bool MainWindow::openImage(const QImage &image, const QString &name)

View File

@ -30,43 +30,50 @@ OcrApplication::OcrApplication(QObject *parent) : QObject(parent)
bool OcrApplication::openFile(QString filePath) bool OcrApplication::openFile(QString filePath)
{ {
qDebug() << __FUNCTION__ << __LINE__ << filePath; qDebug() << __FUNCTION__ << __LINE__ << filePath;
MainWindow *win = new MainWindow(); MainWindow *win = new MainWindow();
win->openFile(filePath); //增加判断,空图片不会启动
win->show(); bool bRet = win->openFile(filePath);
//第一次启动才居中 if (bRet) {
if (m_loadingCount == 0) { win->show();
Dtk::Widget::moveToCenter(win); //第一次启动才居中
m_loadingCount++; if (m_loadingCount == 0) {
Dtk::Widget::moveToCenter(win);
m_loadingCount++;
}
} }
return true;
return bRet;
} }
void OcrApplication::openImage(QImage image) void OcrApplication::openImage(QImage image)
{ {
qDebug() << __FUNCTION__ << __LINE__ << image.size(); //增加判断,空图片不会启动
MainWindow *win = new MainWindow(); if (!image.isNull() && image.width() >= 1) {
win->openImage(image); qDebug() << __FUNCTION__ << __LINE__ << image.size();
win->show(); MainWindow *win = new MainWindow();
//第一次启动才居中 win->openImage(image);
if (m_loadingCount == 0) { win->show();
Dtk::Widget::moveToCenter(win); //第一次启动才居中
m_loadingCount++; if (m_loadingCount == 0) {
Dtk::Widget::moveToCenter(win);
m_loadingCount++;
}
} }
} }
void OcrApplication::openImageAndName(QImage image, QString imageName) void OcrApplication::openImageAndName(QImage image, QString imageName)
{ {
qDebug() << __FUNCTION__ << __LINE__ << image.size(); //增加判断,空图片不会启动
MainWindow *win = new MainWindow(); if (!image.isNull() && image.width() >= 1) {
win->openImage(image, imageName); MainWindow *win = new MainWindow();
win->show(); win->openImage(image, imageName);
//第一次启动才居中 win->show();
if (m_loadingCount == 0) { //第一次启动才居中
Dtk::Widget::moveToCenter(win); if (m_loadingCount == 0) {
m_loadingCount++; Dtk::Widget::moveToCenter(win);
m_loadingCount++;
}
} }
} }