PDA

View Full Version : QThread not starting on second call



boogemin
18th June 2018, 20:35
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


namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
HeatTransferMain *hMain;
QThread T;

signals:
SimData(QString, QString, QString)
}


mainwindow.cpp



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{

ui->setupUi(this);
hMain = new HeatTransferMain;

QThread * T = new QThread;

connect(this,SIGNAL(SimData(QString, QString, QString)),hMain,SLOT(SimulationData(QString, QString,QString))); // Connection of Main Data Structure
}

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.

high_flyer
18th June 2018, 21:41
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.