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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:39:03+00:00 2026-06-01T08:39:03+00:00

I’m trying to implement some small app which is a gui app and has

  • 0

I’m trying to implement some small app which is a gui app and has some heavy work to do as a one of it’s main tasks. Obviously I’m putting this “work” into a separate thread and starting this thread by invoking start fnc on this obj. Unfortunatelly nothing happens. On the other hands when instead of start I invoke implemented fnc run computations are performed as they should although of course in same thread as gui. What to do?
So I have class inheriting QThread:

class Working_Thread : public QThread
{
    Q_OBJECT
public:
    typedef boost::filesystem3::path path_t;

private:
    bool& cancel_flag_;
    const std::set<path_t>& paths_;
    int search_depth_;
    typedef void (Dir_File_Select_Dialog::*fnc_ptr)(const std::set<path_t>&,int);
    fnc_ptr fnc_;
    Dir_File_Select_Dialog* parent_;
protected:
    void run()
    {

        (parent_->*fnc_)(paths_,search_depth_);
    }
public:

    Working_Thread(bool& cancel_flag,const std::set<path_t>&,int&,fnc_ptr fnc,Dir_File_Select_Dialog* parent);


};

And here is fragment from gui thread when I try to start new thread:

 Working_Thread* working_thread = new Working_Thread(cancel_flag,paths,search_depth,&Dir_File_Select_Dialog::extract_files_,this);
        working_thread->start();//this desn't invoke run fnc

but when I do:

working_thread->run();//this will perform computations although in gui thread

UPDATE:
Little change I did which now performs computations when using start fnc but it still blocks GUI.

Working_Thread* working_thread = new Working_Thread(cancel_flag,paths,search_depth,&Dir_File_Select_Dialog::extract_files_,this);
    working_thread->start();//hangs
    working_thread->wait();//when I call wait here computation is performed but GUI is blocked.
  • 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-01T08:39:04+00:00Added an answer on June 1, 2026 at 8:39 am

    I don’t know how your code is actually done, but as a first step i suggest you to follow the best practice suggested at the end of the new revision of the Qt documentation of QThread :

    http://qt-project.org/doc/qt-4.8/QThread.html (look for bottom of this page)

    For a similar tutorial you also may check this article: http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

    Every time i tried to directly make my treatment in a QThread I ended up having big problems with threads (most of time, the treatment beeing done in the caller’s tread).
    This documentation has been added in 4.8 and the examples provided by documentation of previous versions were missleading.

    (code copied from the Qt documentation)
    Consider the following pattern as your default way to use QThread:

    class Worker : public QObject
    {
    Q_OBJECT
    
    public slots:
    void doWork() {
    /* ... */
    }
    };
    
    /* ... */
    QThread *thread = new QThread;
    Worker *worker = new Worker;
    //obj is a pointer to a QObject that will trigger the work to start. It could just be this
    connect(obj, SIGNAL(startWork()), worker, SLOT(doWork()));
    worker->moveToThread(thread);
    thread->start();
    //obj will need to emit startWork() to get the work going.
    

    Alternatively, you could do:

    //based on the same Worker class as above:
    
    /* ... */
    QThread *thread = new QThread;
    Worker *worker = new Worker;
    worker->moveToThread(thread);
    thread->start();
    QMetaObject::invokeMethod(worker, "doWork", Qt::QueuedConnection);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.