Signal "finished" of QNetworkManager
-
Hi,
I tried to have use QNetworkManager to retrieve a information from a server. However it seems the Signal "finished" is not called.
Here is the source:--- Class Implementation
FritzBox::FritzBox()
{
FritzConn.setParent(this);
connect(&FritzConn, SIGNAL(finished(QNetworkReply*)), this, SLOT(ReadFromFritz(QNetworkReply*)));
}void FritzBox::Connect2Fritz()
/**-
Slot that establishes the connection to the Fritzbox by:
-
- cheking if a valid SID exists
-
- if not, then try to connect to Fritz and get a valid SID
-
- if yes: do nothing
**/
{
QString strRequest = "http://fritz.box/login_sid.lua";
(static_cast<MainWindow*>(parent()))->PrintQuery(strRequest);
Reply = FritzConn.get(QNetworkRequest(QUrl(strRequest)));
// connect(Reply, SIGNAL(readyRead()), this, SLOT(readyRead())); - if yes: do nothing
}
void FritzBox::ReadFromFritz(QNetworkReply Reply)
/*- This slot is connected to the TcpClient signal that data is available to read.
- Upon receiving this signal, the data is read and evaluated.
/
{
QByteArray ReadData = Reply->readAll();
FritzAnswer = ReadData;
(static_cast<MainWindow>(parent()))->PrintAnswer("Signal Finished");
(static_cast<MainWindow>(parent()))->PrintAnswer(FritzAnswer);
}
void FritzBox::readyRead()
/**- This slot is connected to the TcpClient signal that data is available to read.
- Upon receiving this signal, the data is read and evaluated.
/
{
QByteArray ReadData = Reply->readAll();
FritzAnswer = ReadData;
(static_cast<MainWindow>(parent()))->PrintAnswer("Signal readyRead");
(static_cast<MainWindow>(parent()))->PrintAnswer(FritzAnswer);
}
--- Class Implementation finished
The method connected to the finished signal is never called. However, if I connect to the "Reply" everything works.
I looked on the www to search for similiar problems. I found some, but their problem usually was, that the QNetworkManager was destroyed before the answer could be read.
This is definitely not the case here. This class is instatiated in MainWindow and is always valid.
So, why is the method connected to the signal "finished" of QNetworkManager not called?
Thanks,
Johannes -
-
@JohK said in Signal "finished" of QNetworkManager:
void FritzBox::ReadFromFritz(QNetworkReply Reply)
Is this a typo? QNetworkReply must be a pointer.
Please use the new Signal/Slot syntax ( https://wiki.qt.io/New_Signal_Slot_Syntax/ ) or check the return value of connect() -
Hello,
thanks.-
the original line is "void FritzBox::ReadFromFritz(QNetworkReply *Reply)
The * got somehow lost upon copying the source to the forum. :-( -
Now I am using the new syntax and all works.
I don't know why the original didn't work, but with the new its OK.
Thanks again,
Johannes -
-
Hello,
thanks.-
the original line is "void FritzBox::ReadFromFritz(QNetworkReply *Reply)
The * got somehow lost upon copying the source to the forum. :-( -
Now I am using the new syntax and all works.
I don't know why the original didn't work, but with the new its OK.
Thanks again,
Johannes -
-
This post is deleted!