Description: Avoid exiting when Tesseract chi_sim data is missing
 Tesseract initialization can fail when chi_sim.traineddata is not
 installed.  The OCR worker must report the failure to the UI instead of
 terminating the whole application.
Author: zhangpan <zhangpan@kylinos.cn>
Bug-Debian: https://bugs.debian.org/1029655
Forwarded: no
Last-Update: 2026-07-07

--- a/src/scanDisplay.cpp
+++ b/src/scanDisplay.cpp
@@ -864,8 +864,11 @@ void myThread::run()
     //使用中文初始化tesseract-ocr，而不指定tessdata路径。正在识别中
     if (api->Init(NULL, "chi_sim")) {
         qDebug()<<"Could not initialize tesseract.\n";
-        outText = "Unable to read text";
-        exit(1);
+        outText = tr("Unable to initialize OCR. Please install tesseract-ocr-chi-sim.");
+        emit orcFinished();
+        delete api;
+        quit();
+        return;
     }
     // 使用leptonica库打开输入图像。
     Pix* image = pixRead("/tmp/scanner/scan1.png");
@@ -876,15 +879,20 @@ void myThread::run()
         emit orcFinished();
         // 销毁使用过的对象并释放内存。
         api->End();
+        delete api;
        // pixDestroy(&image);
         quit();
+        return;
     }
     api->SetImage(image);
     // 得到光学字符识别结果
-    outText = api->GetUTF8Text();
+    char *text = api->GetUTF8Text();
+    outText = QString::fromUtf8(text ? text : "");
+    delete[] text;
     emit orcFinished();
     // 销毁使用过的对象并释放内存。
     api->End();
+    delete api;
     pixDestroy(&image);
     quit();
 }
