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

  • Home
  • SEARCH
  • 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 3230284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:54:32+00:00 2026-05-17T16:54:32+00:00

I’m planning on using qActions for use globally in my application. The idea is

  • 0

I’m planning on using qActions for use globally in my application. The idea is to have an action to be available at any level in the widget parent/child hierarchy.

Let’s say I have the following GUI:

+--------------+
| +----------+ |
| |  +----+  | |
| |  | W2 |  | |
| |  +----+  | |
| |    W1    | |
| +----------+ |
|  MainWindow  |
+--------------+

W2 has a QPushButton which I want to use with a QAction defined in MainWindow. So the question is: What is the recommended way of working with QActions in multiple level hierarchy of widgets?

Here are my approaches:

  1. Define the actions in a MainWindow singleton, and
    access it from W2 to add the qaction
    to the QPushButton.

  2. Define the actions in MainWindow and add them to W1, which in turn
    would add the qaction to W2, which
    in turn would add the action to the
    QPushButton (I don’t like this one).

  3. Create a Delegate singleton class to
    hold qactions and access it from
    MainWindow to make the global
    connections of qactions’ triggers to
    the backend (model), and also access
    it from W2 to add the action wanted
    to the QPushButton.

Thanks

  • 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-17T16:54:32+00:00Added an answer on May 17, 2026 at 4:54 pm

    Personnally, I’d go with a modified version of the second option, in the other way, because it keeps the hierarchy of your program. I say the other way because I would make the w2 pushButton propagate the signal up to the mainWindow. An advantage to this option is that if you add another w2 in w1, you simply have to connect it to w1, your mainWindow will stay exactly the same (encapsulation). Same thing, if you add a w1 in your mainWindow, you only have to connect the new w1 to your mainWindow and you don’t have to care with the pushButton in the w2 of the new w1.

    Here is the code to make this solution works:

    In your w2 class constructor:

    connect(pushButton, SIGNAL(clicked(bool)), this, SIGNAL(buttonClicked(bool)));
    

    In your w1 class constructor:

    connect(widget2, SIGNAL(buttonClicked(bool)), this, SIGNAL(buttonClicked(bool)));
    

    In your mainWindow class constructor:

    connect(widget1, SIGNAL(buttonClicked(bool)), anyAction, SIGNAL(triggered(bool)));
    connect(anyAction, SIGNAL(triggered(bool)), this, SLOT(onActionTriggered(bool)));
    

    Obvisouly, you must define the correct signals/slot in your class definitions and be sure that whatever you connect has already been created.

    Hope this helps.

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

Sidebar

Related Questions

No related questions found

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.