@@ -703,29 +703,42 @@ void EditWrapper::hideWarningNotices()
703703// 除草稿文件 检查文件是否被删除,是否被修复
704704void EditWrapper::checkForReload ()
705705{
706+ qDebug () << __func__;
706707 if (Utils::isDraftFile (m_pTextEdit->getTruePath ())) {
707708 return ;
708709 }
709710
710711 QFileInfo fi (m_pTextEdit->getTruePath ());
711712
712- QTimer::singleShot (50 , [ = ]() {
713- if (fi.lastModified () == m_tModifiedDateTime || m_pWaringNotices->isVisible ()) {
713+ // 使用 QPointer 检查对象是否还存在
714+ QPointer<EditWrapper> self (this );
715+ QTimer::singleShot (50 , [self, fi]() {
716+ if (self.isNull ()) {
717+ qWarning () << " EditWrapper obj is destroyed" ;
718+ return ; // 对象已被销毁
719+ }
720+
721+ if (fi.lastModified () == self->m_tModifiedDateTime || self->m_pWaringNotices ->isVisible ()) {
714722 return ;
715723 }
716724
717- QFileInfo finfo (m_pTextEdit->getTruePath ());
725+ if (self->m_pTextEdit == nullptr ) {
726+ qWarning () << " TextEdit obj is destroyed" ;
727+ return ; // 对象已被销毁
728+ }
729+
730+ QFileInfo finfo (self->m_pTextEdit ->getTruePath ());
718731
719732 if (!finfo.exists ()) {
720- m_pWaringNotices->setMessage (tr (" File removed on the disk. Save it now?" ));
721- m_pWaringNotices->setSaveAsBtn ();
722- m_pWaringNotices->show ();
723- DMessageManager::instance ()->sendMessage (m_pTextEdit, m_pWaringNotices);
724- } else if (!m_tModifiedDateTime.toString ().isEmpty () && finfo.lastModified ().toString () != m_tModifiedDateTime.toString ()) {
725- m_pWaringNotices->setMessage (tr (" File has changed on disk. Reload?" ));
726- m_pWaringNotices->setReloadBtn ();
727- m_pWaringNotices->show ();
728- DMessageManager::instance ()->sendMessage (m_pTextEdit, m_pWaringNotices);
733+ self-> m_pWaringNotices ->setMessage (tr (" File removed on the disk. Save it now?" ));
734+ self-> m_pWaringNotices ->setSaveAsBtn ();
735+ self-> m_pWaringNotices ->show ();
736+ DMessageManager::instance ()->sendMessage (self-> m_pTextEdit , self-> m_pWaringNotices );
737+ } else if (!self-> m_tModifiedDateTime .toString ().isEmpty () && finfo.lastModified ().toString () != self-> m_tModifiedDateTime .toString ()) {
738+ self-> m_pWaringNotices ->setMessage (tr (" File has changed on disk. Reload?" ));
739+ self-> m_pWaringNotices ->setReloadBtn ();
740+ self-> m_pWaringNotices ->show ();
741+ DMessageManager::instance ()->sendMessage (self-> m_pTextEdit , self-> m_pWaringNotices );
729742 }
730743 });
731744}
0 commit comments