[SOLVED]Function pointer
-
wrote on 19 Oct 2012, 11:36 last edited by
Hi gurus!
How i can do something like this:This is the class that stores data item and it has a pointer to function for some manipulation with data
@class VariableItem
{
....
void (*SomeAction)();
}
@This is the main class that stores all data
@class MainClass
{
QList<VariableItem> variableList;
void action1();
void action2();
void action3();
}
@
and as you guess VariableItem::SomeAction must get adress of one action from MainClass
Using global functions solve this but i want use member methods. Maybe Qt already has solution for this cases? -
Seems like a task for signal-slot mechanism.
-
wrote on 19 Oct 2012, 12:15 last edited by
Yeah
But in some cases i need feedback.
@class MainClass
{
QList<VariableItem> variableList;
bool action1(QByteArray *, int *);
bool action2(QByteArray *, int *);
bool action3(QByteArray *, int *);
}@edit
Maybe something like delegates? -
wrote on 19 Oct 2012, 12:19 last edited by
C++ "friend" mechanism can't help?
-
wrote on 19 Oct 2012, 12:22 last edited by
[quote author="qxoz" date="1350648921"]Yeah
But in some cases i need feedback.
@class MainClass
{
QList<VariableItem> variableList;
bool action1(QByteArray *, int *);
bool action2(QByteArray *, int *);
bool action3(QByteArray *, int *);
}@edit
Maybe something like delegates?[/quote]"delegate" means in Qt world a special kind of controller.
Signal/slot can help you beacuse the slot is a "simple" method what can return any arbitrary data.
Maybe the signapmapper is the right choice here. -
wrote on 19 Oct 2012, 12:23 last edited by
Some month ago i saw on this forum topic about creating Arraylist of functions, but i cant find it now. I think there was a solution for me.
-
wrote on 19 Oct 2012, 12:42 last edited by
Can you please show how get return value from signal
@I = emit SomeSignal(); ?@
and will program wait, on emit line, while binded slot is not finished? -
wrote on 19 Oct 2012, 15:49 last edited by
You can get the return value if you invoke the signal through QMetaObject::invokeMethod. If you use the right connection type, the invokation is blocking.
-
wrote on 22 Oct 2012, 04:52 last edited by
Thank you!
QMetaObject::invokeMethod is good solution.
1/9