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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:09:20+00:00 2026-05-15T17:09:20+00:00

I have a simple form UI that has a slot for a button, starting

  • 0

I have a simple form UI that has a slot for a button, starting a thread:

void MainWindow::LoadImage()
{
    aThread->run();
}

And the run() method looks like this:

void CameraThread::run()
{
    qDebug("Staring Thread");
    while(1)
    {
        qDebug("ping");
        QThread::sleep(1);
    }
}

When I click the button that calls LoadImage(), the UI becomes unresponsive. I periodically see the “ping” message as the debug output but the UI hangs, does not respond to anything.
Why is my thread not running separately? CameraThread derived as public QThread
I am using gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) with QT libraries and QT Creator from Ubuntu 10.04(x86) repositories.

  • 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-15T17:09:21+00:00Added an answer on May 15, 2026 at 5:09 pm

    Short answer: Start your thread by calling aThread->start(); not run(), and make sure you thread’s run() method is protected (not public).

    Explanation

    Calling start() is the correct way to start the thread, as it provides priority scheduling and actually executes the run() method in its own thread context.

    It looks like you are going to be loading images in this thread, so I’m going to include some tips before you run into pitfalls many people fall into while using QThread

    1. QThread itself is not a thread. It is just a wrapper around a thread, this brings us to..
    2. signals/slots defined in the CameraThread class will not necessarily run in the thread’s context, remember only the run() method and methods called from it are running in a separate thread.

    IMHO, subclassing QThread in the majority of cases is not the way to go. You can do it much simpler with the following code, and it will save you many headaches.

    class ImageLoader : public QObject {
    Q_OBJECT
    public slots:
        void doWork() 
        {
            // do work
        }
    };
    
    void MainWindow::MainWindow(/*params*/) 
    {
      ImageLoader loader;
      QThread thread;
      loader.moveToThread( &thread );
      connect( this, SIGNAL( loadImage() ), &loader ,SLOT( doWork() ) );
      thread.start();
      // other initialization
    }
    void MainWindow::LoadImage()
    {
       emit loadImage();
    }
    

    Also read the Qt blog regarding this topic.

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

Sidebar

Related Questions

I have a simple login form that has 2 text fields and a button.
I have a very simple XAML form, that has one namespace definition. For some
I currently have a simple form that when you click the save button will
I have a simple html form that looks like the following <form action=search.php method=get>
I have a simple PHP script with a form that has two select fields,
I have a simple password reset form that has a username field, and below
C sharp newbie question...I have a simple asp.net form that has a textbox that
I have a simple contact form on a website that has 2 text fields,
I'm using the CodeIgniter PHP framework. I have a simple form that has an
i have a simple form in my view that has a text area :

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.