QApplication::clipboard()->setMimeData
fileModel->dropMimeData(QApplication::clipboard()->mimeData(), cutOrCopy, 0, 0, qobject_cast<QAbstractItemView *>(focus)->rootIndex());
void FilesCopy::loadFile(QString fPath, QString fDest){ if (fPath.isEmpty()) return; //input file; QFile inputFile(fPath); if (!inputFile.open(QFile::ReadOnly)) { qDebug()<<"Could not open the input file"; } //output file; QFileInfo fileInfo(inputFile.fileName()); QString destination = fDest + (fileInfo.fileName()); qDebug()<<destination; QFile outputFile(destination); if (!outputFile.open(QFile::WriteOnly)) { qDebug()<<"Could not open the output file"; } //div file size to 100; int copyPart = inputFile.size() / 100; int status = 0; //if file size bigger then 100mb; if (inputFile.size() > 104857600) { QByteArray dataFromFile; qint64 tmp = 0; for (int i = 0; i < 100; ++i) { qDebug()<<i<<" i = "<<inputFile.pos()<<"\n"; inputFile.seek(tmp); tmp += copyPart; if (i == 100) { dataFromFile = inputFile.readAll(); } else { dataFromFile = inputFile.read(copyPart); } outputFile.write(dataFromFile); dataFromFile.clear(); ++status; } } else { QFile::copy(fPath, destination); status = 100; } qDebug()<<outputFile.size()<< "= output file\n"; qDebug()<<inputFile.size()<<" = input file\n"; qDebug()<<status; outputFile.flush(); outputFile.close(); emit copyStatus(status);}
void FilesCopy::process(){ //div file size to 100; int copyPart = inputFile.size() / 100; int status = 0; //if file size bigger then 100mb; if (inputFile.size() > 104857600) { QByteArray dataFromFile; qint64 span = 0; for (int i = 0; i < 100; ++i) { qDebug()<<i<<" i = "<<inputFile.pos()<<"\n"; inputFile.seek(span); span += copyPart; if (i == 100) { dataFromFile = inputFile.readAll(); } else { dataFromFile = inputFile.read(copyPart); } outputFile.write(dataFromFile); dataFromFile.clear(); ++status; emit copyStatus(status); } } else { QFile::copy(filePatch, fileDestination); status = 100; } outputFile.flush(); outputFile.close();}
thread = new QThread; fc = new FilesCopy(); connect(fc, SIGNAL(copyStatus(int)), ui->progressBar, SLOT(setValue(int))); connect(thread, SIGNAL(started()), fc, SLOT(process())); fc->moveToThread(thread);void Widget::on_copyBtn_clicked(){ fc->loadFile(file_Source, file_Destionation); thread->start();}