Results 1 to 2 of 2

Thread: QThread not starting on second call

  1. #1
    Join Date
    Jun 2018
    Posts
    1
    Qt products
    Qt5

    Default 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
    Qt Code:
    1. namespace Ui {
    2. class MainWindow;
    3. }
    4. class MainWindow : public QMainWindow
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. explicit MainWindow(QWidget *parent = 0);
    10. ~MainWindow();
    11. HeatTransferMain *hMain;
    12.  
    13. signals:
    14. SimData(QString, QString, QString)
    15. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5.  
    6. ui->setupUi(this);
    7. hMain = new HeatTransferMain;
    8.  
    9. QThread * T = new QThread;
    10.  
    11. connect(this,SIGNAL(SimData(QString, QString, QString)),hMain,SLOT(SimulationData(QString, QString,QString))); // Connection of Main Data Structure
    12. }
    13.  
    14. void MainWindow::on_StartSimulation_Clicked()
    15. {
    16.  
    17. RunMain();
    18. }
    19.  
    20. void MainWindow::Progress()
    21. {
    22. if(ui->listWidget->count()>0)
    23. delete ui->listWidget->takeItem(0);
    24.  
    25. RunMain();
    26. }
    27.  
    28. void MainWindow::RunMain()
    29. {
    30. if(ui->listWidget->count()==0)
    31. return;
    32.  
    33. QString sim_name_it = ui->listWidget->item(0)->text();
    34.  
    35. emit(SimData(sim_name_it, Direc, Path));
    36.  
    37. hMain->DoSetup(T);
    38. hMain->moveToThread(&T);
    39.  
    40. T.start();
    41. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by boogemin; 18th June 2018 at 20:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 15th August 2017, 20:42
  2. QThread - trying to kill a qthread synchronously
    By lhdamiani in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2014, 19:44
  3. Replies: 1
    Last Post: 4th October 2012, 14:49
  4. QThread - Still having issues
    By sgrant327 in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2010, 13:31
  5. QThread issues. Crash after 2058 runs.
    By zverj in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2009, 10:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.