hvengel
24th May 2007, 22:31
I am using QUrlOperator::copy to copy files as part of setting up user configuration information the first time the app is run. I had this setup as part of the main() function and was running it before I started any dialogs. Since QUrlOperator::copy runs asynchronously I have been concerned that it might be possible that the files might not have been copied by the time the first dialog opens. In the past there were 4 fairly small files being copied and it has not been an issue. But current development code now has 6 files and soon another 2 will be added. Some users testing with current development code are now starting to experience problems with this and I am in the process of setting this up so that the first dialog blocks before it needs the files until the file copy operation is complete.
I have this working but I am seeing some strange problems that I don't understand. The basic issue is that I am seeing 2 finished signals for each copy operation and not 1 like I had expected.
My code looks like this:
Globals
static QUrlOperator urlOpTempFile;
static QMutex mutexTempFile;
static int copyNumTempFile = 0;
Slot to handle finished signal
void lprofMain::templateFileCopied( QNetworkOperation *op )
{
mutexTempFile.lock();
if ( !op )
return;
if ( op->state() == QNetworkProtocol::StFailed )
{
QMessageBox::critical( this, tr( "ERROR" ), op->protocolDetail() );
}
else if(op->state() == QNetworkProtocol::StDone)
{
copyNumTempFile = copyNumTempFile - 1;
}
mutexTempFile.unlock();
}
Routine that starts the copy operations with a "fix"
void lprofMain::Create_Config_Dir(const QString data_path)
{
// Copy the template files into the users config directory
QDir d (data_path + QString("/template/"));
d.setFilter(QDir::Files | QDir::Hidden);
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi = it.current()) != 0 )
{
++it;
if (fi->fileName().contains("ITX", FALSE))
{
mutexTempFile.lock();
copyNumTempFile = copyNumTempFile + 1;
urlOpTempFile.copy( data_path + QString("/template/") +
fi->fileName(), dir->homeDirPath() +
QString("/.lprof/templates/") );
// next line is the "fix"
copyNumTempFile = copyNumTempFile + 1;
mutexTempFile.unlock();
}
}
}
}
main dialog creation code
lprofMain::lprofMain( QWidget* parent)
: lprofMainBase( parent, "", 0,)
{
QObject::connect( &urlOpTempFile, SIGNAL( finished( QNetworkOperation *) ), this, SLOT( templateFileCopied( QNetworkOperation * ) ) );
Create_Config_Dir(QDir::currentDirPath());
while (copyNumTempFile>0)
{
lprofApp -> processEvents();
}
}
I am running Qt 3.3.8 on a Linux box. Anyone seen this type of thing before or have any ideas about what could be causing this? The code above works but my main concern is that it does not look right to me and I am concerned that I may be "fixing" something that is really a problem with the particular version of Qt I am running.
I have this working but I am seeing some strange problems that I don't understand. The basic issue is that I am seeing 2 finished signals for each copy operation and not 1 like I had expected.
My code looks like this:
Globals
static QUrlOperator urlOpTempFile;
static QMutex mutexTempFile;
static int copyNumTempFile = 0;
Slot to handle finished signal
void lprofMain::templateFileCopied( QNetworkOperation *op )
{
mutexTempFile.lock();
if ( !op )
return;
if ( op->state() == QNetworkProtocol::StFailed )
{
QMessageBox::critical( this, tr( "ERROR" ), op->protocolDetail() );
}
else if(op->state() == QNetworkProtocol::StDone)
{
copyNumTempFile = copyNumTempFile - 1;
}
mutexTempFile.unlock();
}
Routine that starts the copy operations with a "fix"
void lprofMain::Create_Config_Dir(const QString data_path)
{
// Copy the template files into the users config directory
QDir d (data_path + QString("/template/"));
d.setFilter(QDir::Files | QDir::Hidden);
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi = it.current()) != 0 )
{
++it;
if (fi->fileName().contains("ITX", FALSE))
{
mutexTempFile.lock();
copyNumTempFile = copyNumTempFile + 1;
urlOpTempFile.copy( data_path + QString("/template/") +
fi->fileName(), dir->homeDirPath() +
QString("/.lprof/templates/") );
// next line is the "fix"
copyNumTempFile = copyNumTempFile + 1;
mutexTempFile.unlock();
}
}
}
}
main dialog creation code
lprofMain::lprofMain( QWidget* parent)
: lprofMainBase( parent, "", 0,)
{
QObject::connect( &urlOpTempFile, SIGNAL( finished( QNetworkOperation *) ), this, SLOT( templateFileCopied( QNetworkOperation * ) ) );
Create_Config_Dir(QDir::currentDirPath());
while (copyNumTempFile>0)
{
lprofApp -> processEvents();
}
}
I am running Qt 3.3.8 on a Linux box. Anyone seen this type of thing before or have any ideas about what could be causing this? The code above works but my main concern is that it does not look right to me and I am concerned that I may be "fixing" something that is really a problem with the particular version of Qt I am running.