For design reasons, I need to come up with a way to call QObject::connect()
where the function pointers are passed in as returned values of function calls. Namely, instead of using the vanilla syntaxconnect(sender, &Sender::valueChanged, receiver, &Receiver::updateValue);
, I have to do something like the following:
//in main.cpp
SENDER *sender = new SENDER;
RECEIVER *receiver = new RECEIVER;
connect(sender, sender->get_func(), receiver, receiver->get_func() );
where SENDER and RECEIVER are defined as follows:
//sender.h
#include <QWidget>
class SENDER : public QWidget{
Q_OBJECT
public:
void(* get_func() ) (double, double);
signals:
void send_data(double x, double y);
};
//sig_sender.cpp
#include "sender.h"
void (* SENDER::get_func() )(double, double)
{
return send_data;
}
//sig_receiver.h
#include <QWidget>
class RECEIVER : public QWidget{
Q_OBJECT
public:
void receive_data(double x, double y);
void(* get_func() ) (double, double);
};
//sig_receiver.cpp
#include "receiver.h"
void (* RECEIVER::get_func() )(double, double)
{
return receive_data;
}
Attempts to compile give me the following error:
/home/abc/work/mainwindow.cpp:14: error: no matching function for call to ‘MainWindow::connect(SENDER*&, void (*)(double, double), RECEIVER*&, void (*)(double, double))’
connect(sender, sender->get_func(), receiver, receiver->get_func() );
What am I doing wrong here?
Aucun commentaire:
Enregistrer un commentaire