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. Use Qthread in a Qt Console application
Forum Updated to NodeBB v4.3 + New Features

Use Qthread in a Qt Console application

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.8k 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.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Greetings.

    I wanted to know how to use QThread in a console application (an application without GUI). I don't know how and when to start the threads and general, how reconciling the work with threads and QCoreApplication.

    Thanks in advance for any help and/or suggestions.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is nothing specific about Threading in core application. "When to Use" thread itself is topic. You can goole around and you will get good number of topics. The same rule applies here as well.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        "Here":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ is a good explanation on how to use QThread in general.

        If you need to start a thread immediately after application is started then put it to main()
        @
        QCoreApplication a(argc, argv);

        // Here is thread initialization and start
        QThread* thread = new QThread;
        Worker* worker = new Worker();
        worker->moveToThread(thread);
        connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)));
        connect(thread, &QThread::started, worker, &Worker::process);
        connect(worker, &QThread::finished, thread, &QThread::quit);
        connect(worker, &QThread::finished, worker, &Worker::deleteLater);
        connect(thread, &QThread::finished, thread, &QThread::deleteLater);
        connect(thread, &QThread::finished, &a, &QCoreApplication::quit);
        thread->start();

        // Start app event loop
        return a.exec();
        @

        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