LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2011, 09:40 AM   #1
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Compilation error trying to sub-class a Qt QAction class, not sure why


Hi all,

As the title says, I am trying to sub-class a standard Qt QAction class so that I can create an action trigger that sends a QString text message to the event handler. That way I can simply create one event handler for a context menu I need to present and have the event handler figure out which menu item was selected by examining the passed text string. I got the code from an article I read on the net and am including a copy of it.

Code:
class MyAction : public QAction  

{  

  Q_OBJECT  

  public:  

    MyAction(QString someActionInfo)  

      : someActionInfo_(someActionInfo)  

    {  

      connect(this, SIGNAL(triggered()),  

              this, SLOT(onTriggered()));  

    }  

  signals:  

    void triggered(QString someActionInfo);  

  private slots:  

    void onTriggered() {  

      emit triggered(someActionInfo_);  

    }  

  private:  

    QString someActionInfo_;  

};
I am also including a link to the article in case anyone else wants to take a look at it: http://schneide.wordpress.com/tag/qt4/

The error I am receiving is "no matching function call to 'QAction::QAction()'. The error is being generated by the constructor line. I am not sure why the error is being generated, the code looks okay to me. Any help on figuring out what the error is referring to is greatly appreciated.
 
Old 02-08-2011, 11:34 AM   #2
wshackle
LQ Newbie
 
Registered: May 2008
Posts: 6

Rep: Reputation: 0
Try


MyAction(QObject * parent,QString someActionInfo)

: QAction(parent),someActionInfo_(someActionInfo)

{

QAction doesn't have a zero arguments constructor
 
Old 02-08-2011, 11:45 AM   #3
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Original Poster
Rep: Reputation: 38
Yup, that works. For anyone else who may want to try something like this, here is what I finally did:

Code:
class MyAction : public QAction  
{  
  Q_OBJECT  

  public:
    explicit MyAction(QString someActionInfo, QObject *parent)  
      : QAction(someActionInfo, parent)
    {
      someActionInfo_ = someActionInfo;
      connect(this, SIGNAL(triggered()), this, SLOT(onTriggered()));  
    }

  signals:  
    void triggered(QString someActionInfo);

  private slots:  
    void onTriggered() {  
      emit triggered(someActionInfo_);  
    }  

  private:  
    QString someActionInfo_;  
};
You can then set up an event handler to receive a QString. When triggered, the event handler is called and the text originally passed in during the action instantiation is also passed as the QString variable.

Thank you wshackle!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Python n00b: promoting a derived class to base class? CoderMan Programming 2 03-11-2010 01:46 PM
C++ templated Node class: pointers to different instantated class types jhwilliams Programming 3 08-20-2007 06:20 PM
Derived class inside parent class array, possible? xemous Programming 3 10-17-2006 11:35 AM
Does derivated class inherit base class destructor (constructor)? kornerr Programming 2 08-23-2006 08:05 AM
Which C++ editor in Linux has the class view/class browser feature imaginationworks Programming 7 05-21-2006 11:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration