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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:16:16+00:00 2026-05-14T07:16:16+00:00

I’m a new bit in Qt… I have a Qt GUI application (written by

  • 0

I’m a new bit in Qt…

I have a Qt GUI application (written by me), let’s call it QtAPP.exe
When QtAPP.exe running, I will use a QThread and QProcess to execute some external file,
such as player.exe (written in native C).

Here’s my question:
In QtAPP.exe, there are 2 classes,
1. QMainWindow – Core of QtAPP.exe
2. QThread – A thread class to execute external things

For now, if I got a finished() signal in that QThread,
how do I to force the QMainWindow to repaint itself ?

Hope somebody can show me some tips, maybe sample code 🙂
Any suggestion are welcome~

  • 1 1 Answer
  • 1 View
  • 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-14T07:16:16+00:00Added an answer on May 14, 2026 at 7:16 am

    One solution would be to simply connect the finished() signal to a slot in MainWindow whose implementation calls update(). Note that delivery of this signal will be asynchronous because the sender and receiver objects are in different threads.

    Here is a working example:

    main.cpp

    #include <QtGui/QApplication>
    #include "stuff.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        MainWindow w;
        w.show();
        return app.exec();
    }
    

    stuff.h

    #ifndef STUFF_H
    #define STUFF_H
    
    #include <QtGui/QMainWindow>
    #include <QtCore/QThread>
    
    class QLabel;
    
    class Thread : public QThread
    {
        Q_OBJECT
    public:
        Thread(QObject *parent);
        void run();
    
    private:
        void startWork();
    
    signals:
        void workFinished();
    };
    
    class MainWindow : public QWidget
    {
        Q_OBJECT
    public:
        MainWindow();
    
    public slots:
        void startWork();
        void workFinished();
    
    private:
        QLabel* m_label;
        Thread* m_thread;
    };
    
    #endif
    

    stuff.cpp

    #include <QtCore/QTimer>
    #include <QtCore/QMutex>
    #include <QtCore/QWaitCondition>
    #include <QtGui/QVBoxLayout>
    #include <QtGui/QPushButton>
    #include <QtGui/QLabel>
    #include "stuff.h"
    
    #include <QDebug>
    
    // Global variables used for ITC
    QWaitCondition buttonPressed;
    QMutex mutex;
    
    Thread::Thread(QObject *parent)
        :   QThread(parent)
    {
    
    }
    
    void Thread::run()
    {
        qDebug() << "Thread::run" << QThread::currentThreadId();
        while (1) {
            mutex.lock();
            buttonPressed.wait(&mutex);
            mutex.unlock();
            startWork();
        }
    }
    
    void Thread::startWork()
    {
        qDebug() << "Thread::startWork" << QThread::currentThreadId();
        // Simulate some long-running task
        sleep(3);
        // Emit a signal, which will be received in the main thread
        emit workFinished();
    }
    
    
    MainWindow::MainWindow()
        :   m_label(new QLabel(this))
        ,   m_thread(new Thread(this))
    {
        QPushButton *button = new QPushButton("Start", this);
        connect(button, SIGNAL(pressed()), this, SLOT(startWork()));
    
        QVBoxLayout *layout = new QVBoxLayout(this);
        layout->addWidget(button);
        layout->addWidget(m_label);
        setLayout(layout);
    
        // Create connection across thread boundary
        connect(m_thread, SIGNAL(workFinished()), this, SLOT(workFinished()));
    
        m_thread->start();
    }
    
    void MainWindow::startWork()
    {
        // Signal the thread to tell it that the button has been pressed
        mutex.lock();
        m_label->setText("Started");
        buttonPressed.wakeAll();
        mutex.unlock();
    }
    
    void MainWindow::workFinished()
    {
        qDebug() << "MainWindow::workFinished" << QThread::currentThreadId();
        m_label->setText("Finished");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.