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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:30:27+00:00 2026-05-23T01:30:27+00:00

I am trying to run a background thread (qthread) that needs to monitor a

  • 0

I am trying to run a background thread (qthread) that needs to monitor a checkbox in the gui and it will not run! It builds but during runtime i get this error:

“Unhandled exception at 0x0120f494 in program.exe: 0xC0000005: Access violation reading location 0xcdcdce55.”

and it breaks on the “connect” line. What is the best way to do this?

guiclass::guiclass(){
    thread *t = new thread();
}

thread::thread(){
     guiclass *c = new guiclass();
     connect(c->checkBox, SIGNAL(stateChanged(int)), this, SLOT(checked(int)));

     ....
     start work
     ....
}

bool thread::checked(int c){
     return(c==0);
}

void thread::run(){

    if(checked()){
        do stuff
    }
}
  • 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-23T01:30:28+00:00Added an answer on May 23, 2026 at 1:30 am

    The event queue of any QThread object is actually handled by the thread that started it, which is quite unintuitive. The common solution is to create a “handler” object (derived from QObject), associate it with your worker thread by calling moveToThread, and then bind the checkbox signal to a slot of this object.

    The code looks something like this:

    class ObjectThatMonitorsCheckbox : public QObject
    {
         Q_OBJECT
         // ...
    
    public slots:
         void checkboxChecked(int checked);
    }
    

    In the code that creates the thread:

    QThread myWorkerThread;
    
    ObjectThatMonitorsCheckbox myHandlerObject;
    
    myHandlerObject.moveToThread(&myworkerThread);
    connect(c->checkBox, SIGNAL(stateChanged(int)), &myHandlerObject, 
        SLOT(checkboxChecked(int)));
    
    myWorkerThread.start();
    

    One key point: Don’t subclass QThread — all the actual work is done in your handler object.

    Hope this helps!

    See also: Qt: Correct way to post events to a QThread?

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

Sidebar

Related Questions

I am trying to monitor a thread that i set running in the background.
I'm trying to work out how to run a process in a background thread
How to run a thread in background, after the device is rebooted. I'm trying
I am trying to run a thread continuously and not have it become blocked
I'm trying to run a service in the background that sends texts messages of
Some background info: I'm trying to run a server program in python 2.5.1 (the
Im trying to make a countdown timer run in the background of my activity,
Trying to run Jison unit tests, but the command fails. How do I fix
I am trying to put some complex computations on a background thread using dispatch_async
I am trying to perform an operation on a background thread. In the past

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.