oh yeah... my bad. Thanks.
I'm still stuck (predictably). In short, what I'm trying to do is create a class--TextureAction--that is a subclass of QAction and behaves exactly like QAction, except for two things:
1) TextureAction will have a variable, int myValue, that can be set by a member function, mySetVariable.
2) my TextureAction class will have a QSignalMapper object to take QAction's triggered() SIGNAL, pass it to my QSignalMapper SLOT, and then signal this back out as an integer. Sounds simple enough, but when I instantiate a TextureAction object, I get the following error:
error C2440: '=' : cannot convert from 'QAction *' to 'TextureAction *'
Cast from base to derived requires dynamic_cast or static_cast
textureAction.h and .cpp look like this:
#include <QSignalMapper>
#include <QAction>
//#include <QWidget>
//class QSignalMapper;
//class QAction;
class TextureAction
: public QAction{
Q_OBJECT
public:
// TextureAction(int value, QObject *parent);
void setValue(int x) { Value = x; }
signals:
void myClicked(int value);
private:
int Value;
};
//+++ and .cpp below
#include "textureAction.h"
#include <QAction>
TextureAction
::TextureAction(QAction *parent
){
// connect(myAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
// signalMapper->setMapping(myAction, Value);
// connect(signalMapper, SIGNAL(mapped(Value)), this, SIGNAL(myClicked(Value)));
}
#include <QSignalMapper>
#include <QAction>
//#include <QWidget>
//class QSignalMapper;
//class QAction;
class TextureAction : public QAction
{
Q_OBJECT
public:
// TextureAction(int value, QObject *parent);
TextureAction(QAction *parent);
void setValue(int x) { Value = x; }
signals:
void myClicked(int value);
private:
QSignalMapper *signalMapper;
int Value;
};
//+++ and .cpp below
#include "textureAction.h"
#include <QAction>
TextureAction::TextureAction(QAction *parent)
: QAction(parent)
{
signalMapper = new QSignalMapper(this);
QAction *myAction = new QAction(this);
// connect(myAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
// signalMapper->setMapping(myAction, Value);
// connect(signalMapper, SIGNAL(mapped(Value)), this, SIGNAL(myClicked(Value)));
}
To copy to clipboard, switch view to plain text mode
In my Window.cpp code (my main Qt application window) I'm declaring a TextureAction object like so:
tAction1 = menu->addAction(tr("Topography")); // TextureAction *tAction1; declared in .h file
//tAction1 = new TextureAction; //this also fails
pButton2 = new QPushButton(tr("&Terrain\n Texture"));
menu = new QMenu(this);
tAction1 = menu->addAction(tr("Topography")); // TextureAction *tAction1; declared in .h file
//tAction1 = new TextureAction; //this also fails
To copy to clipboard, switch view to plain text mode
If my TextureAction class is derived from QAction, can't I use a TextureAction object in nearly the same way as I could a QAction object? (like add it to the QMenu, as I've done above?)
Bookmarks