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. [Solved] Threads not running concurrently

[Solved] Threads not running concurrently

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.9k 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.
  • H Offline
    H Offline
    Hareen Laks
    wrote on last edited by
    #1

    Hi,

    I'm watching "this":http://www.youtube.com/watch?v=JaGqGhRW5Ks video tutorial.

    I created three threads as same as mentioned there.

    @#include <QtCore/QCoreApplication>
    #include "mythread.h"

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    Mythread mthread1;
    mthread1.setObjectName("mthread1");
    
    Mythread mthread2;
    mthread2.setObjectName("mthread2");
    
    Mythread mthread3;
    mthread3.setObjectName("mthread3");
    
    mthread1.run();
    mthread2.run();
    mthread3.run();
    
    return a.exec&#40;&#41;;
    

    }@

    And my run() method like below.

    @void Mythread::run()
    {

    qDebug()<< this->objectName() << "Running";
    
    for(int i =0; i<100000;i++)
    {
       qDebug()<< this->objectName() << i;
    }
    

    }@

    When I compile and run the app threads not running concurrently. They run one after the other.
    But In tutorial video they are running concurrently.

    What is the problem?

    Thanks in advance.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hareen Laks
      wrote on last edited by
      #2

      Sorry my friends. I used @mthread1.run();@ instead of @mthread1.start();@

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi,
        The use of QThread is wrong in that video!! Skip to part 5 where he explains why!

        Greetz, Jeroen

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hareen Laks
          wrote on last edited by
          #4

          @ Jeroentje,

          Ohh. really?
          Thank you very much for the information.. I'll move to part 5..

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Better read this part:
            "Your text to link here...":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

            The QThread class is very low level way of programming multithreaded applications! You might want to look into QtConcurrent classes! There the threads are run in the background and makes it much more easy to run multithreads safely!
            "QtConcurrent":http://qt-project.org/doc/qt-5.0/qtconcurrent/qtconcurrent-index.html

            Greetz, Jeroen

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hareen Laks
              wrote on last edited by
              #6

              Thank you Jeroentje. I'll read those.

              Thanks again.

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                Hi,

                Maya's blog and Qt Concurrent aren't the whole story. For example, Qt Concurrent cannot be used for threads that last for a long time, or for inter-thread communication.

                There are a few different ways to do multithreading in Qt. This page compares all of them, and helps users choose an appropriate method: http://qt-project.org/doc/qt-5/threads-technologies.html

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hareen Laks
                  wrote on last edited by
                  #8

                  Thank you JKSH.

                  I still haven't got time to read it. But I'll read it ASAP.

                  1 Reply Last reply
                  0

                  • Login

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