[Qt-interest] problem with threaded qfile renaming
Andrei Sebastian Cimpean
andreiamenta at gmail.com
Sun Jun 27 09:58:10 CEST 2010
Hello everybody,
I stumbled upon a strange problem while doing a batch renaming in another
thread.
This is the code I'm working with. It is the first time I use QThread so if
you spot any problems please let me know. QStringlist
fileOperationsStringSecondContainer holds the full path of the selected files
and fileOperationsStringFirstContainer holds the new name for the file. They
have the same size and in debugging mode they hold the correct values. The
problem is that file.rename(fileOperationsStringFirstContainer.at(i) doesn't
work as it should. I've used this before but in the main thread and in the
same app with no problems. While debugging it "file" appears as unavailable.
I've tried declaring it a pointer and submitting as a parameter in the
QFile::rename the full path with the new file name but, either way, the file I
am trying to rename disappears.
void RenameFileOperations::run(){
for(int i=0;i<fileOperationsStringSecondContainer.count();i++){
QFile file;
file.setFileName(fileOperationsStringSecondContainer.at(i));
qDebug() << file.fileName() << file.exists()
if(file.rename(fileOperationsStringFirstContainer.at(i)) == false){
batchRenamingMutex.lock();
emit needUserDecision(i);
while(decision == ""){
batchRenamingWaitCondition.wait(&batchRenamingMutex);
}
batchRenamingMutex.unlock();
QFile::rename(fileOperationsStringSecondContainer.at(i),decision);
decision = "";
}
else{
//the operation was succesfull
}
}
}
/**
*
*/
void RenameFileOperations::decisionSet(bool resume, QString newname){
this->decision = newname;
if(resume == false){
this->setTerminationEnabled(true);
}
else{
this->batchRenamingWaitCondition.wakeAll();
}
}
In the main thread I link the signal emitted by the renaming thread with:
void MultipleFileRename::renameNeedsDialogBox(int positionWhereItStopped){
QString message("Unfortunately the name you chose for this file already
exists.\nPlease supply another one or modify\n the existing one.");
bool ok;
QString text = QInputDialog::getText(0, tr("QInputDialog::getText()"),
message, QLineEdit::Normal,
calculatedFileNames.at(positionWhereItStopped),
&ok);
renameOperation->decisionSet(true,text);
}
I think there is a big chance I also messed up a bit with the threading
system, so if you spot big stupid things please point them out.
I sought help on the irc room #qt, but unfortunately we weren't able to figure
it out.
Thank you.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100627/b2278aae/attachment.bin
More information about the Qt-interest-old
mailing list