Connection/Slot question
-
I have the following Class in creation that looks like so
@class CQueryHandler : public QObject
{
Q_OBJECTpublic:
CQueryHandler(QObject* pParent = 0);
bool Initialize();
~CQueryHandler();public:
void SendQuery(const QString& strQuery);protected slots:
void QueryFinished(QNetworkReply* pNetReply);private:
QNetworkAccessManager* m_pNetworkManager;
QByteArray m_ByteArray;} g_QueryHandler;@
@
CQueryHandler::CQueryHandler(QObject* pParent)
: QObject(pParent), m_pNetworkManager(NULL)
{}
bool CQueryHandler::Initialize()
{
// Initialized Network Manager
m_pNetworkManager = new QNetworkAccessManager(this);
if (m_pNetworkManager == NULL) {
return false;
}// Setup Connections
connect(m_pNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(QueryFinished(QNetworkReply*)));
}void CQueryHandler::QueryFinished(QNetworkReply* pNetReply)
{
// TODO: Error checking// Perform Parsing and extra things from returned query // Extract Data from reply to a QByteArray Object m_ByteArray = pNetReply->readAll();
}@
This is just a rough outline of what i have. Pretty much i have CRequestHandler...Which will request my webserver for a particular Query and upon completion and retrieval of the information will perform some extra processing and parsing and save the information in my BYTEARRAY member.
If my program is using the above global object( g_QueryHandler ), and i have a simple dialog with a button the user can click, i understand how to send the QueryRequest as shown below
@void Dialog::Clicked()
{
g_QueryHandler.SendQuery("somequery to send to webserver");
}@But what im unsure of is how to INFORM my Dialog:: that the request has finished and the above Dialog:: object can check the Query information returned from the request inside of g_QueryHandler.m_ByteArray member variable?
-
Add this to CQueryHandler's definition:
@signals:
void queryFinished();
@Add this to Dialog's definition:
@public slots:
void queryHandlerFinished();
@Add this to Dialog:Dialog():
@
connect( &g_QueryHandler, SIGNAL( queryFinished() ), SLOT( queryHandlerFinished() ) );
@In the implementation of queryHandlerFinished() do whatever you want.
-
Don't forget to actually emit that signal too, for example at the end of your CQueryHandler::QueryFinished method:
@
emit queryFinished();
@ -
Oh, yes, forgot to mention. Thanks.