QThread not starting on second call
Hello, I am having a trouble getting a thread to continue restarting until a listWidget is finished with all of the items in it.
mainwindow.h
Code:
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
HeatTransferMain *hMain;
signals:
}
mainwindow.cpp
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
hMain = new HeatTransferMain;
}
void MainWindow::on_StartSimulation_Clicked()
{
RunMain();
}
void MainWindow::Progress()
{
if(ui->listWidget->count()>0)
delete ui->listWidget->takeItem(0);
RunMain();
}
void MainWindow::RunMain()
{
if(ui->listWidget->count()==0)
return;
QString sim_name_it
= ui
->listWidget
->item
(0)->text
();
emit(SimData(sim_name_it, Direc, Path));
hMain->DoSetup(T);
hMain->moveToThread(&T);
T.start();
}
When the Thread is done for the first Sim_name_it, the progress function is emitted by the thread. The Progress function calls RunMain(), but the thread never starts. Any ideas will be helpful!
note: the code was edited for readability, if something is not defined it was probably removed because it was deemed not important.
Re: QThread not starting on second call
I don't know if this is THE problem, but its A problem:
You have declared QThread T; member that you use in RunMain(), and in your code you are defining a local *T pointer as well, but the T.start() in RunMain is starting the member, not the thread pointer.
In any case you have two instances of QThread that I think you tread as if they were only one.