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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:08:18+00:00 2026-06-10T04:08:18+00:00

I have some slot function defined in my class which do some actions. I

  • 0

I have some slot function defined in my class which do some actions. I wanted to create a possibility to allow the user of my class to define his own slot function (replacing the function from my class for his own). I tried to achieve it by pointer to a slot function this way:

class asd {
    Q_OBJECT

private:
    void ( asd::*m_funcTrigger )( QAction* );

public:
    asd();
    // and some method to pass the pointer

private slots:
    void actionTrigger( QAction* );

};

the constructor:

asd::asd() {
    // set the slot function from class as default
    m_funcTrigger = &asd::actionTrigger;

    // m is a QMenu object
    connect(m, SIGNAL(triggered(QAction*)), this, SLOT(m_funcTrigger(QAction*)));
}

actionTrigger’s implementation is not important I think.

So, when I put actionTrigger into the SLOT() it works ok. When I put there the m_funcTrigger it doesn’t – nothing happens (the slot is not found by the Qt). I was sure that it is beacuse the pointer is not in the slots section in the class, so I just put it there:

private slots:
    void ( asd::*m_funcTrigger )( QAction* );
    void actionTrigger( QAction* );

but I got strange error:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(151,5): error MSB6006: “cmd.exe” exited with code 1.

I completely don’t know how to deal with this.

EDIT:

I think the reason why it’s not found by the Qt:
From what I have read over the Internet, the SLOT() just returns a simple const char* which includes identifier name of the method passed to the SLOT, Therefore the Qt completely doesn’t know what the pointer is pointing at. It just looks after the m_funcTrigger( QAction* ) function.

I created another solution (which works I will put it here later I’m currently at work) that requires the user of the class to pass a SLOT(hisOwnFunction()) into the function which sets the slot function. Because the class uses signal-slots idea, so it’s Qt dependent and I think because of that it’s ok to pass SLOT there instead of a pointer. What do you think?

  • 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-10T04:08:19+00:00Added an answer on June 10, 2026 at 4:08 am
    1. You can make your slot virtual, so derived class can override it.

    2. You can call m_funcTrigger in your slot by yourself:

      private slots:
          void actionTrigger_slot( QAction* a)
          {
           m_funcTrigger(a);
          }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function which calculates some value based on multiple slots of multiple
I've defined some signal: typedef boost::signals2::signal<void (int temp)> SomeSig; typedef SomeSig::slot_type SomeSigType; I have
I have a global object X and a class A. I need a function
I have some constructor for the class LCDRange: LCDRange::LCDRange(QWidget *parent) : QWidget(parent) { QLCDNumber
I have to create a table with cells on which by clicking I have
I have following code: class A { public: A(); private: void slot(); }; The
I have an XNA game (its a slot machine). I have some really cool
I am working in cross platform C++, and have some classes defined like so:
I have some data loaded as a np.ndarray and need to convert it to
I have some arbitrary pixel data that I want to save as a PNG.

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.