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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:00:13+00:00 2026-05-23T08:00:13+00:00

I have a class extending QWidget class and this class uses a Ui class

  • 0

I have a class extending QWidget class and this class uses a Ui class generated by QtDesigner. Something like following:

class MyWidget : public QWidget
{
   signals:
            void pushButtonClicked();
   // ....
   private:
            Ui::MyUi ui;

}

MyWidget::MyWidget()
{
    ui = new Ui::MyUi();
    ui->setupUi(this);
}

Now lets suppose there is a QPushButton * pushButton field inside Ui::MyUi. The UI for this widget has no complex business logic.

Now it is required that whenever pushButton is clicked this widget should emit a signal (lets call it pushButtonClicked(). Now the only way I can imagine this to be achieved is to:

  1. connect clicked() signal of pushButton object to a local slot and emit signal pushButtonClicked()from there.

  2. Install MyWidget as mouseEventFilter for pushButton and handle it inside MyWidget::mouseClickedEvent

Are there other options? Like somehow letting Qt framework to use ‘MyWidget::pushButtonClicked()’ instead of pushButton->clicked()

In the project I have many scenarios like this where such signal passing is needed from the wrapper classes like MyWidget, which wrap/abstract the UI by aggregation or inheritance. In general which is considered the best approach for better design, code reuse esp. when the project is at nascent stage and it is not known which of these UIs might need complex business logic in the future.

Please note that extending QPushButton is not an option.

  • 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-23T08:00:14+00:00Added an answer on May 23, 2026 at 8:00 am

    You can connect signals directly =)

    connect(pushButton , SIGNAL(clicked()), this, SIGNAL(pushButtonClicked()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class extending android.os.Handler . An instance of this handler is passed
I have a class extending PreferenceActivity: public class PreferenceActivity extends android.preference.PreferenceActivity { @Override protected
I have an intermediary class extending System.Web.UI.Page for all of my pages that require
Currently I have a class that is extending the ListActivity class. I need to
I have two classes in a PHP application, B extending A for example. Class
I have class A: public class ClassA<T> Class B derives from A: public class
I have a class extending mysqli. It follows a singleton pattern so I have
Suppose I have class animal and classes cat and dog extending it. I want
I have an abstract class Abstr<T> and an extending class Ext<T> . I need
I have an abstract class extending Composite (AbstractWhiteBoard). Then I have a concrete class

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.