First, a common pattern to wrap asychronous operations together with their context is the job or command pattern.
Each command object has its context, can be started and signals success/failure.
A sequence command can then get a list of smaller commands and start one after the previous one has succeeded.
Things like "check if dir exists, create if not" can also be combined in a composite command which can then be used in the sequence.
See also this blog http://cmollekopf.wordpress.com/2014...re-it-belongs/
Second, any event loop based asynchronous operation in Qt can, with some caution, behave synchronous by using a local event loop instance, e.g. using a helper function
void runCommand
(QFtp *ftp,
int commandId
) {
connect(ftp, SIGNAL(commandFinished(int, bool)), &loop, SLOT(quit()));
loop.exec();
}
void runCommand(QFtp *ftp, int commandId)
{
QEventLoop loop;
connect(ftp, SIGNAL(commandFinished(int, bool)), &loop, SLOT(quit()));
loop.exec();
}
To copy to clipboard, switch view to plain text mode
runCommand(ftp, ftp->mkdir(d));
runCommand(ftp, ftp->mkdir(d));
To copy to clipboard, switch view to plain text mode
Alternatively use something like a QProgressDialog to provide both the local event loop and keeping the user from interacting with the rest of the application.
Cheers,
_
Bookmarks