Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Can not Start multiple Thread

    General and Desktop
    2
    2
    43
    Loading More Posts
    • 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.
    • Ketan__Patel__0011
      Ketan__Patel__0011 last edited by Ketan__Patel__0011

      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 Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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 Reply Quote 2
        • First post
          Last post