I think I have found the problem. It wasn't calling QAction ( QObject * parent, const char * name ) but another constructor that I had: MyAction(QObject *, bool).
But why a "myaction *action = new MyAction(this, "name")" could call that constructor with a bool argument? I don't get it.
And the problem is that I really need that constructor.
Your code modified:
#include <QtGui>
#include <QtDebug>
{
public:
MyAction
(QObject* parent,
const QString
& name
);
};
MyAction
::MyAction(QObject* parent,
const QString
& name
){
qDebug() << "MyAction::MyAction()";
setText(name);
setObjectName(name);
}
{
qDebug() << "MyAction::MyAction(QObject, bool)";
}
{
public:
};
MainWindow
::MainWindow(QWidget* parent
){
qDebug() << "MainWindow::MainWindow()";
MyAction * action = new MyAction(this, "Action");
menuBar()->addAction(action);
}
int main(int argc, char* argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui>
#include <QtDebug>
class MyAction : public QAction
{
public:
MyAction(QObject* parent, const QString& name);
MyAction(QObject *parent, bool a);
};
MyAction::MyAction(QObject* parent, const QString& name)
: QAction(parent)
{
qDebug() << "MyAction::MyAction()";
setText(name);
setObjectName(name);
}
MyAction::MyAction(QObject *parent, bool a) : QAction(parent)
{
qDebug() << "MyAction::MyAction(QObject, bool)";
}
class MainWindow : public QMainWindow
{
public:
MainWindow(QWidget* parent = 0);
};
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
qDebug() << "MainWindow::MainWindow()";
MyAction * action = new MyAction(this, "Action");
menuBar()->addAction(action);
}
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
After running it, console output:
MainWindow::MainWindow()
MyAction::MyAction(QObject, bool)
Bookmarks