snow_man_0:可以自己写一个CopyFileEx函数,不用别人的
 (2021-08-23 07:59) 
 
bool copyFileA(QString &srcPath, QString &dstPath)
{
    QFile file(srcPath);
    qWarning()<<"file size="<<file.size();
    QByteArray s = srcPath.toLatin1();
    char *src = (char*)s.data();
    QByteArray d = dstPath.toLatin1();
    char *dst = (char*)d.data();
    ifstream in(src, ios::binary);
    ofstream ou(dst, ios::binary);
    if(!in.is_open())
    {
        qWarning()<<"src is open failed!";
        emit sigCopyValue(m_nCopyValue);
        return false;
    }
    if(dst == src)
    {
        qWarning()<<"the src file can't be same with dst file";
        emit sigCopyValue(m_nCopyValue);
        return false;
    }
    char buffer[64*1024] = {0};
    long long totalBytes = 0;
    qWarning()<<"hello...";
    //m_mutex2.lock();
    while(in)
    {
        in.read(buffer, 64*1024);
        ou.write(buffer, in.gcount());
        totalBytes += in.gcount();
        m_nCopyValue = (int)((totalBytes*1.0/file.size())*100);
        qWarning()<<"copyValue="<<m_nCopyValue;
        QElapsedTimer et;
        et.start();
        while(et.elapsed() < 25)
        {
            emit sigCopyValue(m_nCopyValue);
            QCoreApplication::processEvents();
        }
        if(totalBytes == file.size())
            break;
    }
    //m_mutex2.unlock();
    in.close();
    ou.close();
    qWarning()<<"fstream close";
    return true;
}
我自己也写了一个类似CopyFileEx的函数,但是在同时启动两个线程去拷贝两个大于1GB的文件时,它直接进入那个循环,然后就不停的发信号,可能是发信号太快了,主线程没有来的及回复,导致了主界面还是会卡顿、假死,请问以上的代码,可以做哪些优化或修改吗?