void QuebrarSenha::quebrarSenhaZIP() { QString text = ui->lineEdit->text(); QThread *workerThread; CountWorker *worker; int i; //Esta é a parte mais importante do programa; //Está sendo criado 4 threads, onde cada thread é responsável por executar uma porção das senhas em paralelo //As senhas variam de 0 a 500000 for(i = 0; i < 4; i++){ workerThread = new QThread; QLabel *label; if(i==0) label=ui->thread0; else if(i==1) label=ui->thread1; else if(i==2) label=ui->thread2; else if(i==3) label=ui->thread3; worker = new CountWorker(i*125000, (i+1)*125000, text, label); worker->moveToThread(workerThread); connect(workerThread, SIGNAL(started()), worker, SLOT(doWork())); connect(worker, SIGNAL(finished()), workerThread, SLOT(quit())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); connect(worker, SIGNAL(updateCount(int, QLabel*)), this, SLOT(updateCount(int, QLabel*))); connect(worker, SIGNAL(updateSenha(int)), this, SLOT(updateSenha(int))); connect(worker, SIGNAL(updateProgressBar(float)), this, SLOT(updateProgressBar(float))); workerThread->start(); } }
void HardDiskDialog::SetupTransferPane() { ui->forwardButton->setEnabled(false); ui->backButton->setEnabled(false); ui->CountingFrame->setVisible(true); root = QDir(AllTransfersDir.path()); root.cd(ui->TransferList->selectedItems().at(0)->text()); QThread *thread = new QThread; CountWorker *worker = new CountWorker(root); worker->moveToThread(thread); connect(thread, SIGNAL (started()), worker, SLOT (startWork())); connect(worker, SIGNAL (finished(qulonglong, QTreeWidgetItem*)), thread, SLOT (quit())); connect(worker, SIGNAL (finished(qulonglong, QTreeWidgetItem*)), worker, SLOT (deleteLater())); connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater())); connect(worker, SIGNAL (finished(qulonglong, QTreeWidgetItem*)), this, SLOT (countWorkerDone(qulonglong, QTreeWidgetItem*))); thread->start(); }