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 710497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:37:37+00:00 2026-05-14T04:37:37+00:00

I am using Qt and wish to write a class that will perform some

  • 0

I am using Qt and wish to write a class that will perform some network-type operations, similar to FTP/HTTP. The class needs to connect to lots of machines, one after the other but I need the applications UI to stay (relatively) responsive during this process, so the user can cancel the operation, exit the application, etc. My first thought was to use a separate thread for network stuff but the built-in Qt FTP/HTTP (and other) classes apparently avoid using threads and instead rely on signals and slots. So, I’d like to do something similar and was hoping I could do something like this:

class Foo : public QObject
{
  Q_OBJECT
public:
  void start();

signals:
  void next();

private slots:
  void nextJob();
};

void Foo::start()
{
  ...
  connect(this, SIGNAL(next()), this, SLOT(nextJob()));
  emit next();
}

void Foo::nextJob()
{
  // Process next 'chunk'

  if (workLeftToDo)
  {
    emit next();
  }
}


void Bar::StartOperation()
{
   Foo* foo = new Foo;
   foo->start();
}

However, this doesn’t work and UI freezes until all operations have completed. I was hoping that emitting signals wouldn’t actually call the slots immediately but would somehow be queued up by Qt, allowing the main UI to still operate.

So what do I need to do in order to make this work? How does Qt achieve this with the multitude of built-in classes that appear to perform lengthy tasks on a single thread?

  • 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-05-14T04:37:38+00:00Added an answer on May 14, 2026 at 4:37 am

    If you’re doing a length job in the UI thread the UI is going to freeze. One way to avoid this is to call once in a while QCoreApplication::processEvents().

    You should be VERY careful however to understand what this does before you decide to do it. Calling this function means that a GUI event can fire in the middle of your operation. If this event can in turn create some more jobs you can end up starting a new job while in the middle of the old job.

    I wouldn’t be so quick dismissing the worker thread approach. It has the advantage of completely separating the work from the GUI so you are certain that something that began is going to finish.
    You should also consider that Windows especially sometimes introduces non trivial delays to GUI loops. If the host is somewhat busy or in a memory thrashing state you’ll find that GUI events may take up to several long seconds to finish and return control to your processing.

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

Sidebar

Related Questions

In using a function, I wish to ensure that the type of the variables
In some unit/integration tests of the code we wish to check that correct usage
I have CPU bound application that I wish to speedup using multiprocessing+threading instead of
I wish to automagically discover some information on a provided class to do something
I have an XElement instance and I wish to write to a stream using
I'm using constructor injection for the first time and wish to write my code
I have a type library called MyCOMAddin.tlb , that I have extracted using tlbexp.exe
So I'm trying to write a base class to handle classes that wrap std::vector,
I wish to do this using only XAML - How to add an additional
I wish to deploy multiple instances of wcf webservice using MSI installer.When i tried

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.