lukas.zachy
16th November 2010, 22:44
Hello all,
I begin to play with Qt and got stuck with QNetworkAccessManager.
I can not find any difference to the provided example (googlesuggest), but the example works and my code does not :(
It seems that the network manager doesn't emit finished signal.
The project consists of two classes, one is GUI, second should should access web.
debugging output is:
Starting D:\documents\programming\slovnik-prekladac-qt\Dict-build-desktop\debug\Dict.exe...
translateText called
translateText ends
D:\documents\programming\slovnik-prekladac-qt\Dict-build-desktop\debug\Dict.exe exited with code 0
header:
#ifndef TRANSLATE_H
#define TRANSLATE_H
#include <QString>
#include <QtNetwork>
class Translate :public QObject
{
Q_OBJECT
public:
Translate();
void translateText(QString which);
public slots:
void dataRcd(QNetworkReply *nt);
signals:
void textTranslated(QString *result);
private:
QNetworkAccessManager netmanager;
};
#endif // TRANSLATE_H
code:
#include "translate.h"
#include <QtDebug>
Translate::Translate()
{
QObject::connect(&netmanager,SIGNAL(finished(QNetworkReply*)),this,S LOT(dataRcd(QNetworkReply*)));
}
void Translate::dataRcd(QNetworkReply *nt){
qDebug()<<"dataRcd called";
emit textTranslated(new QString ("slot dataRcd called"));
}
void Translate::translateText(QString which){
qDebug() <<"translateText called";
emit textTranslated(new QString("pre network manager"));
QNetworkRequest req(QUrl("http://www.google.com"));
netmanager.get(req);
qDebug()<<"translateText ends";
}
Any advice or hint would be a great help.
Cheers
lukas
I begin to play with Qt and got stuck with QNetworkAccessManager.
I can not find any difference to the provided example (googlesuggest), but the example works and my code does not :(
It seems that the network manager doesn't emit finished signal.
The project consists of two classes, one is GUI, second should should access web.
debugging output is:
Starting D:\documents\programming\slovnik-prekladac-qt\Dict-build-desktop\debug\Dict.exe...
translateText called
translateText ends
D:\documents\programming\slovnik-prekladac-qt\Dict-build-desktop\debug\Dict.exe exited with code 0
header:
#ifndef TRANSLATE_H
#define TRANSLATE_H
#include <QString>
#include <QtNetwork>
class Translate :public QObject
{
Q_OBJECT
public:
Translate();
void translateText(QString which);
public slots:
void dataRcd(QNetworkReply *nt);
signals:
void textTranslated(QString *result);
private:
QNetworkAccessManager netmanager;
};
#endif // TRANSLATE_H
code:
#include "translate.h"
#include <QtDebug>
Translate::Translate()
{
QObject::connect(&netmanager,SIGNAL(finished(QNetworkReply*)),this,S LOT(dataRcd(QNetworkReply*)));
}
void Translate::dataRcd(QNetworkReply *nt){
qDebug()<<"dataRcd called";
emit textTranslated(new QString ("slot dataRcd called"));
}
void Translate::translateText(QString which){
qDebug() <<"translateText called";
emit textTranslated(new QString("pre network manager"));
QNetworkRequest req(QUrl("http://www.google.com"));
netmanager.get(req);
qDebug()<<"translateText ends";
}
Any advice or hint would be a great help.
Cheers
lukas