Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can not Start multiple Thread
Forum Updated to NodeBB v4.3 + New Features

Can not Start multiple Thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 118 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Ketan__Patel__0011
    wrote on 14 Sept 2020, 07:33 last edited by Ketan__Patel__0011
    #1

    Hello friend currently i am working on parallel processing concepts

    i want run my 2 or 3 functions parallelly

    when i start Thread Number 1 on my button click event that time Thread one is started but after thread number 1 is started i can't perform any other operation in my application until Thread number 1 process is not finished

    My Application GUI Is :
    Capture.PNG

    My Code is :

       #include "mainwindow.h"       
       #include "ui_mainwindow.h"
                     
       MainWindow::MainWindow(QWidget *parent) :  QMainWindow(parent),      
           ui(new Ui::MainWindow)       
       {       
       ui->setupUi(this);          
         
      TestingThread_1 = new QThread();      
      connect(TestingThread_1,SIGNAL(started()),this,SLOT(Start_Processing_1()));      
              
      TestingThread_2 = new QThread();       
      connect(TestingThread_2,SIGNAL(started()),this,SLOT(Start_Processing_2()));
                    
      TestingThread_3 = new QThread();    
      connect(TestingThread_3,SIGNAL(started()),this,SLOT(Start_Processing_3()));      
       }
                     
       MainWindow::~MainWindow()       
       {       
           delete ui;       
       }       
              
       void MainWindow::Start_Processing_1()       
       {       
           for(i = 0 ; i < 100 ; i++)       
           {       
               ui->label->setText(QString::number(i + 1));       
               QThread::msleep(20);       
               qDebug() << i;       
           }       
       }
                     
       void MainWindow::Start_Processing_2()       
       {       
           for(int i = 0 ; i < 100 ; i++)       
           {       
               ui->label_2->setText(QString::number(i + 1));       
               QThread::msleep(20);       
               qDebug() << i;       
           }       
       }
                     
       void MainWindow::Start_Processing_3()       
       {       
           for(int i = 0 ; i < 100 ; i++)       
           {       
               ui->label_3->setText(QString::number(i + 1));       
               QThread::msleep(20);       
               qDebug() << i;       
           }       
       }
                     
       void MainWindow::on_pushButton_clicked()       
       {       
           TestingThread_1->start();       
       }              
       
       void MainWindow::on_pushButton_2_clicked()       
       {       
           TestingThread_2->start();       
       }              
       
       void MainWindow::on_pushButton_3_clicked()       
       {       
           TestingThread_3->start();       
       }
    

    please friends help me to solve this problem
    Thanks in Advance

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 14 Sept 2020, 07:49 last edited by
      #2

      The methods Start_Processing_1(), Start_Processing_2() and Start_Processing_3() are run in your main thread. Your QThread instances do nothing.

      Please read and use the docs, the way QThread works is described in detail there. https://doc.qt.io/qt-5/qthread.html

      In short:

      • either subclass QThread and reimplement run()
      • or use worker object approach

      (Z(:^

      1 Reply Last reply
      2

      1/2

      14 Sept 2020, 07:33

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved