hardgeus
27th December 2006, 15:51
In my application I have run into a situation (SFTP downloading) where I need to repeatedly loop for quite a bit of time inside of an event. As of right now, my whole app is frozen during the download, which is of course not desirable.
My first instinct is to use a QThread for the download, but that would require a fair amount of re-coding of the existing app. Is there a way I could hand back control to the app's event pump during my loop? I was thinking of something like this:
//Called from my button click slot
int DownloadFile() {
if( m_Semaphore ) {
return(0);
}
m_Semaphore = 1; //To keep this function from being called again during download
int bytesleft = checkfilesize();
while( bytesleft ) {
bytesleft -= downloadsomedata();
//Is there something I could call like this that allows app
//Event loop to continue?
::AllowMessagePumpToRun();
}
m_Semaphore = 0;
} //DownloadFile
I know this isn't the world's most desirable solution, but I was hoping that I could accomplish this without a major rewrite of this code. The SFTP overhead I have in my class is somewhat bulky, and I doin't want to have to move all of this over into a new class. (I know, it was a bad idea to tie all of this functionality into my Window class)
My first instinct is to use a QThread for the download, but that would require a fair amount of re-coding of the existing app. Is there a way I could hand back control to the app's event pump during my loop? I was thinking of something like this:
//Called from my button click slot
int DownloadFile() {
if( m_Semaphore ) {
return(0);
}
m_Semaphore = 1; //To keep this function from being called again during download
int bytesleft = checkfilesize();
while( bytesleft ) {
bytesleft -= downloadsomedata();
//Is there something I could call like this that allows app
//Event loop to continue?
::AllowMessagePumpToRun();
}
m_Semaphore = 0;
} //DownloadFile
I know this isn't the world's most desirable solution, but I was hoping that I could accomplish this without a major rewrite of this code. The SFTP overhead I have in my class is somewhat bulky, and I doin't want to have to move all of this over into a new class. (I know, it was a bad idea to tie all of this functionality into my Window class)