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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:36:11+00:00 2026-05-27T20:36:11+00:00

This is inside a Menu class. The problem is addAction. This works, but there

  • 0

This is inside a Menu class. The problem is addAction. This works, but there is no connection to slot:

QMenu* menu2 = new QMenu("Test");
menu2->addAction("Test");

When I do this:

QMenu* menu2 = new QMenu("Test");
menu2->addAction("Test", Menu, test);

I get compiler error: “error: expected primary-expression before ‘,’ token”

I mean to call the test() function in the Menu class. What am I doing wrong?

  • 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-27T20:36:12+00:00Added an answer on May 27, 2026 at 8:36 pm

    Well, the error comes from passing Menu as an argument. You say Menu is a class, and classes are not expressions on themselves.

    If you need to call test on an instance of Menu, where Menu is not a derivate from QObject (ie. no slots available), then you can just create a slot in the widget that contains the QMenu itself (probably a QMainWindow), and implement the call in there!

    Edit: to add an example.

    class MainWindow : public QMainWindow {
      Q_OBJECT
     // Usual declarations...
    
    private slots:
      void myCustomSlot();
    };
    

    Now, say that you’re populating the main window inside its constructor:

    MainWindow::MainWindow(...) {
       // Some initialization code
    
       QMenu *menu2 = new QMenu("Test");
       menu2->addAction("Test", this, SLOT(myCustomSlot));
       // Some more initialization code
    }
    
    // ...
    
    void MainWindow::myCustomSlot() {
       instanceOfMenu->test();
    }
    

    Of course, if you’re creating the menu outside that class, you’d need to make the slot public, but that’s another issue

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

Sidebar

Related Questions

I have a Image XML menu that works well, but with a litle problem
I have this code inside a class that is used by an application and
So I have this code inside my lib/ folder: class GlobalConfig::SetHelper def self.yes_no_input(configuration) value
I have this div inside a repeater, where i set the class, onmouseover and
Note: I have a workaround to this problem, but I'd prefer to comma-separate the
This code works fine in IE8/7 and Firefox... But in Google Chrome i got
This is my first question here but I'm sure there are many more to
I'm developing a html with this structure div id=menuContainer> <div class = menu ui-accordion-header
This may seem weird but I have a problem in one of my programs
It seems that i cannot access $(this) inside jquery ajax success function. please see

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.