The solution may be simple. Then again it may not be possible.

I have the base callback class:

Qt Code:
  1. class CFCallback {
  2. int command_;
  3. int transfer_rate_;
  4. public:
  5. CFCallback(int command, int transfer_rate = 0) {
  6. command_ = command; transfer_rate_ = transfer_rate; }
  7. virtual ~CFCallback() {}
  8. virtual void operator()(void *data) = 0;
  9. int GetCommand() { return command_; }
  10. int GetTransferRate() { return transfer_rate_; }
  11. };
To copy to clipboard, switch view to plain text mode 

And here's one example of deriving from CFCallback:

Qt Code:
  1. void CFPacketVersion::InitiateVersion() {
  2. class InitiateVersionCB : public CFCallback {
  3. CFPacketVersion *visitor_;
  4. public:
  5. InitiateVersionCB(CFPacketVersion *v, int command) :
  6. CFCallback(command) {
  7. visitor_ = v;
  8. }
  9. void operator()(void *data) {
  10. Packet *pkt = (Packet *)data;
  11. unsigned char *pkt_data = pkt->GetData();
  12. std::string version = "";
  13. for(unsigned int i = 0; i < pkt->GetDataLength(); i++ )
  14. version+= pkt_data[i];
  15. delete []pkt_data;
  16. boost::regex rex("CFA(.*?):h(.*?),v(.*?)$");
  17. boost::smatch what;
  18. if( boost::regex_match(version, what, rex) ) {
  19. if(visitor_->GetModel()->GetName() != what[1].str() )
  20. LCDInfo("Crystalfontz: Model mismatch");
  21. visitor_->SetHardwareVersion(what[2]);
  22. visitor_->SetFirmwareVersion(what[3]);
  23. }
  24. }
  25. };
  26. GetVersion(new InitiateVersionCB(this, 1));
  27. }
To copy to clipboard, switch view to plain text mode 

GetVersion(CFCallback *) is provided to the script engine.

I want to be able to do the same thing as seen in InitiateVersion, but on the javascript side of things. Is that possible?

I know I need to register meta type info for CFCallback. But I don't know if it's possible to use a pointer to a CFCallback. What I tried initially didn't work.

Also, seeing as CFCallback is a functor, I'm not sure how I translate that over to javascript. I imagine I can make CFCallback a QObject and provide a signal emitted from operator(). If you have any tips, please share.