@@ -12,15 +12,17 @@ FileLoadThread::FileLoadThread(const QString &filepath, QObject *parent)
1212 : QThread(parent),
1313 m_strFilePath(filepath)
1414{
15-
15+ qDebug () << " Creating FileLoadThread for file: " << filepath;
1616}
1717
1818FileLoadThread::~FileLoadThread ()
1919{
20+ qDebug () << " Destroying FileLoadThread for file:" << m_strFilePath;
2021}
2122
2223void FileLoadThread::run ()
2324{
25+ qDebug () << " Starting file load thread for:" << m_strFilePath;
2426 QFile file (m_strFilePath);
2527
2628 if (file.open (QIODevice::ReadOnly)) {
@@ -30,9 +32,11 @@ void FileLoadThread::run()
3032 // 判断文件大小是否超过40MB, 超过40MB的文件过大,需要调整读取策略,优先加载头部文件
3133 static const int s_maxDirectReadLen = 40 * DATA_SIZE_1024 * DATA_SIZE_1024;
3234 if (file.size () > s_maxDirectReadLen) {
35+ qDebug () << " Large file detected (" << file.size () << " bytes), using optimized loading strategy" ;
3336 // 先读取1MB数据
3437 indata = file.read (DATA_SIZE_1024 * DATA_SIZE_1024);
3538 encode = DetectCode::GetFileEncodingFormat (m_strFilePath, indata);
39+ qDebug () << " Initial encoding detection result:" << encode;
3640
3741 // 发送文件头信息,用于预先加载数据
3842 QString textEncode = QString::fromLocal8Bit (encode);
@@ -47,18 +51,21 @@ void FileLoadThread::run()
4751
4852 // 读取申请开辟内存空间时,捕获可能出现的 std::bad_alloc() 异常,防止闪退。
4953 try {
54+ qDebug () << " Reading remaining file content" ;
5055 // reads all remaining data from the file.
5156 indata += file.read (file.size ());
5257 file.close ();
58+ qDebug () << " Total bytes read:" << indata.size ();
5359 } catch (const std::exception &e) {
54- qWarning () << Q_FUNC_INFO << " Read file data error, " << QString ( e.what ()) ;
60+ qWarning () << " FileLoadThread read error: " << e.what () << " at " << m_strFilePath ;
5561
5662 file.close ();
5763 emit sigLoadFinished (encode, indata, true );
5864 return ;
5965 }
6066
6167 if (encode.isEmpty ()) {
68+ qDebug () << " Performing full encoding detection" ;
6269 // 编码识别,如果文件数据大于1M,则只裁剪出1M文件数据去做编码探测
6370 QByteArray dateUsedForCodeIdentify;
6471 if (indata.length () > DATA_SIZE_1024 * DATA_SIZE_1024) {
@@ -70,15 +77,21 @@ void FileLoadThread::run()
7077 }
7178
7279 QString textEncode = QString::fromLocal8Bit (encode);
80+ qDebug () << " Final encoding detected:" << textEncode;
7381 if (textEncode.contains (" ASCII" , Qt::CaseInsensitive) || textEncode.contains (" UTF-8" , Qt::CaseInsensitive)) {
82+ qDebug () << " Using original encoding, no conversion needed" ;
7483 emit sigLoadFinished (encode, indata, false );
7584 } else {
85+ qDebug () << " Converting from" << textEncode << " to UTF-8" ;
7686 QByteArray outData;
7787 DetectCode::ChangeFileEncodingFormat (indata, outData, textEncode, QString (" UTF-8" ));
7888 emit sigLoadFinished (encode, outData, false );
89+ qDebug () << " Encoding conversion completed, output size:" << outData.size ();
7990 }
8091 }
8192
93+ qDebug () << " FileLoadThread finished processing:" << m_strFilePath;
8294 this ->quit ();
8395 this ->deleteLater ();
96+ qDebug () << " FileLoadThread resources cleaned up" ;
8497}
0 commit comments