I am passing a signal to a method using the SIGNAL macro, and at some point I need to emit that signal.
Something like the below:
void Network::get(const QNetworkRequest &request, const char *signal)
{
QNetworkReply *reply = m_manager->get(request);
m_requests.insert(reply, signal);
}
void Network::get(const QNetworkRequest &request, const char *signal)
{
QNetworkReply *reply = m_manager->get(request);
m_requests.insert(reply, signal);
}
To copy to clipboard, switch view to plain text mode
the Network class encapsulates QNetworkAccessManager, so in the method above m_manager is QNetworkAccessManager.
The Network class has the following signal/slot connection:
connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onResponse(QNetworkReply*)));
connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onResponse(QNetworkReply*)));
To copy to clipboard, switch view to plain text mode
the onResponse SLOT is:
void Network::onResponse(QNetworkReply *reply)
{
const char *signal = m_requests.take(reply);
// emit signal somehow
qDebug() << "and the signal is: " << signal;
}
void Network::onResponse(QNetworkReply *reply)
{
const char *signal = m_requests.take(reply);
// emit signal somehow
qDebug() << "and the signal is: " << signal;
}
To copy to clipboard, switch view to plain text mode
m_request is: QHash<QNetworkReply *, const char *> m_requests;
The idea is that various other classes of the application can use the Network class to make http requests. Each of those classes calls void Network::get(const QNetworkRequest &request, const char *signal) passing its own signal that should be emitted once the request is finished.
I prototype a small concept of the application using PySide and this mechanism of passing the signal worked perfectly.
But in the C++ version the return of the SIGNAL macro is a const char *, is there a way i can turn the const char * back to an emittable signal?
Bookmarks