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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:23:16+00:00 2026-06-14T22:23:16+00:00

I want to create a QMenu that contains QAction objects that are checkable. Once

  • 0

I want to create a QMenu that contains QAction objects that are checkable. Once an action is checked, it will fire and enable drawing of some 3D object. However, the number of 3D objects depends on what files to be loaded. Thus, this QMenu have dynamic number of QAction objects. Suppose we have 10 3D objects with names “1”, “2”, … “10” and thus the QAction objects in the QMenu would be displayed as “1”, “2”, … “10”. When one of these are checked, 3D object of that name will be enabled to display.

Code to generate dynamic QAction objects:

QStringList labels = defaultScene->getLabels();
for(int i=0; i<labels.size(); i++){
     QAction* labelAction = new QAction(labels[i], this);
     labelAction->setToolTip("Trace Marker " + labels[i]);
     labelAction->setStatusTip("Trace Marker " + labels[i]);
     labelAction->setCheckable(true);
     traceMenu->addAction(labelAction);
}

My question is, how do I connect these QAction objects? Specifically, I have an array of bool in defaultScene that will be toggled as the QAction are toggled. How am I to know which QAction is firing? The SIGNAL of QAction on toggle only passes through a bool. Ideally, I would have a single function in defaultScene:

void toggleObject3D(int index){
     if(index >= 0 && index < visibleSize){
          visible[index] = !visible[index];
     }
}

So to make this work, I would need some sort of SIGNAL from traceMenu that would fire an int variable. I am unaware of such SIGNAL.

  • 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-14T22:23:18+00:00Added an answer on June 14, 2026 at 10:23 pm

    You can use QSignalMapper (Link in the documentation)

    The idea is to associate each QAction with an index, and then use the mapped(int) signal from QSignalMapper. Of course, we need to map the toggled signal.

    So first, define your method toggleObject3D as a slot.

    Then, when generating the instances of QAction, create the QSignalMapper and associate each action with it:

    QStringList labels = defaultScene->getLabels();
    QSignalMapper *mapper = new QSignalMapper(this);
    for(int i=0; i<labels.size(); i++){
       QAction* labelAction = new QAction(labels[i], this);
       labelAction->setToolTip("Trace Marker " + labels[i]);
       labelAction->setStatusTip("Trace Marker " + labels[i]);
       labelAction->setCheckable(true);
       traceMenu->addAction(labelAction);
    
       // Map this action to index i
       mapper->setMapping(labelAction, i);
       // Associate the toggled signal to map slot from the mapper
       // (it does not matter if we don't use the bool parameter from the signal)
       connect(action, SIGNAL(toggled(bool)), mapper, SLOT(map()));
    }
    
    // Connect the QSignalMapper map() signal to your method
    connect(mapper, SIGNAL(mapped(int)), this, SLOT(toggleObject3D(int)));
    

    And it should work 🙂

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

Sidebar

Related Questions

I want create a tarball that when extracted the file(s) will be placed at
I want create constructor that will take one or more integers and save it
I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want to create a new field (or two) in my table that is
I want create texture atlas(matrix of images) from multiple images.Is their any applescript that
I want create a cache so that when an item doesn't exist, only one
I want create a function that verify if the numbers of a list fall
I want create something that looks like the MSN Messenger chat forms. I am
i want create a counter that retrieve the number of month, day, hour, minute

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.