Here is my code:
void FileOperations::EncryptAndSave(Ui::MainWindow *NUI){
int Stime = clock();
int percent=0;
NUI->progressBar->setVisible(1);
while(percent<100)
{
if(clock()-Stime>250)
{
percent++;
NUI->progressBar->setValue(percent);
Stime=clock();
}
Sleep(1);
}
CFuncion=0;
NUI->progressBar->setVisible(0);
}
I wan’t this loop to not freeze the whole program after a few seconds, is this possible, or do i need multi-threading?
If multithreading is the only option, could someone give me some example code (With sending variables to the second thread)
I was gonna put the code in main.cpp and just let it run every time it checks over the code, but in QT, main.cpp only executes once.
Btw, this is an example code, obviously it does nothing yet, im gonna put some file operations in the loop.
QCoreApplication::processEvents()shall be called in you loop to avoid UI freeze.