Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:03:14+00:00 2026-06-13T12:03:14+00:00

I have been learning Qt for a while and a few days ago I

  • 0

I have been learning Qt for a while and a few days ago I decided to go on multi-threading by QThread. I have been following this person. Since he says that subclassing QThread is not the appropriate way but by using QObject is. I am following his method. But he has created another class which inherits from QObject. I decided to make a few changes:

class myclass
{
private:
    dowork();

private slots:
    slota();
    slotb();
    slotc();
}

myclass::dowork()
{
    QThread lett;
    QThread latt;
    QThread pltt;
    QObject lethread;
    connect(&lett, SIGNAL(started()), this, SLOT(slota()));
    lethread.moveToThread(&lett);
    QObject lathread;
    connect(&latt, SIGNAL(started()), this, SLOT(slotb()));
    lathread.moveToThread(&latt);
    QObject plthread;
    connect(&pltt, SIGNAL(started()), this, SLOT(slotc()));
    plthread.moveToThread(&pltt);

    lett.start();    
    latt.start();
    pltt.start();/*
    lett.wait();
    latt.wait();
    pltt.wait();*/
    while(lett.isRunning())
    {
        //qDebug() << "Still Running!";
    }
    lett.quit();
}

If I run the program it keeps running while loop infinitely! It doesn’t come out of that at all.
I used qdebug inside the implementation of the 3 slots to check whether it is entering them or not, and surprisingly none of the slots gets called. Why is that so?
If I remove the comments for .wait then the program pauses.

What is wrong in this method? I want to avoid that extra class as my program is very small.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:03:15+00:00Added an answer on June 13, 2026 at 12:03 pm
    while(lett.isRunning())
    {
        //qDebug() << "Still Running!";
    }
    lett.quit();
    

    Terribly wrong. The current thread is busy waiting and will be eating all the time. But this is not your problem. Your problem is certainly that the main event loop has probably not started yet, ie you didn’t do QApplication.exec() yet.

    Qt uses events to start threads, and when you do use movetoThread, start, specific events are queued in the current thread (ie the thread executing these methods). If the main event loop has already started, then will be processed as soon as they can. But in your case I bet that you main function is :

     int main(){
       QApplication app();
       myclass onlyclassIwanttomake;
       onlyclassIwanttomake.dowork(); 
       app.exec(); <----HERE!!!
     }
    

    The thread will be started when the main thread executes app.exec();. When you are busy waiting, you are preventing the main thread to process the events required to start your
    events.

    EDIT: Well, another issue is that

    lett.start();    
    latt.start();
    pltt.start();
    

    start 3 threads which are started, and stay idle forever. They are not doing anything, but they are running (even if you remove your loop).

    This is a entry written about Qt threading. Please take the time to read it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning python for some time now. While starting this learning python
Still learning JSP Web Applications here. I have been doing this for a while
I've been learning Android for a while now and have decided on making an
This is a shoutout as I've been spending the last few days learning about
I have been learning Python for a while, and now I'd like to learn
I have been learning Hibernate for the past few weeks, I have gotten most
I have been lurking and learning in here for a while. Now i have
So been a few days now learning about web references within my projects I
I have been learning GWT and Hibernate together for the last few weeks and
I have been learning PHP/Mysql for a while. But don't yet know enough to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.