QTcpSocket i bazujac na tym, co znalazlem w dokmuentacji, napisalem cos takiego: (kod ponizej - maksymalnie prosty, bo na razie chce tylko zrozumiec zasade dzialania QTcpSocket) Jednak nie dziala chyba w cale, nie wiem, gdzie jest problem… Nic mi nie wyswietla ten qDebug, wiec nie wiem nawet, czy prawidlowo obsluzeylem polaczenie. Bylbym ogromnie wdzieczny za pomoc
KLASA.H
#ifndef KLASA_H
#define KLASA_H
#include
#include
#include
class moja : public QWidget{
Q_OBJECT
public:
moja();
private:
QTcpSocket* socket;
QString strona;
protected slots:
void onReadyRead();
};
#endif // KLASA_H
KLASA.CPP
#include "klasa.h"
#include
#include
#include
moja::moja(){
socket = new QTcpSocket();
QUrl url("http://www.onet.pl");
socket->connectToHost(url.host(), 80);
connect(socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()) );
}
void moja::onReadyRead() {
QByteArray temp=socket->readAll();
QString nowy(temp);
strona=nowy;
qDebug()<
}
MAIN.CPP
#include "klasa.h"
#include
int main(int a, char**b){
QApplication app(a,b);
moja m;
m.show();
return app.exec();
}
– Dodane 30.12.2009 (Śr) 13:19 – Ok, troche pogrzebalem i mam - ale dalej nie dziala mi poprawnie- teraz wyswietla mi, ze strona nie istenieje, a istnieje napewno … KLASA.H
#ifndef KLASA_H
#define KLASA_H
#include
#include
#include
///Dialog showing a website
class GofunHelp : public QDialog
{
Q_OBJECT
public:
GofunHelp();
public slots:
void httpData(int,bool);
private:
QTextBrowser* textbrowser;
QHttp* http;
};
#endif // KLASA_H
KLASA.CPP
#include
#include
#include "klasa.h"
#include
GofunHelp::GofunHelp()
{
QGridLayout* gl = new QGridLayout(this);
textbrowser = new QTextBrowser(this);
gl->addWidget(textbrowser,0,0);
http = new QHttp();
connect(http,SIGNAL(requestFinished(int,bool)),this,SLOT(httpData(int,bool)));
http->setHost("www.lastfm.pl",80);
http->get("http://www.lastfm.pl/music/Placebo/Without+You+I'm+Nothing");
}
void GofunHelp::httpData(int id, bool error)
{
if(error)
{
qDebug()<errorString();
return;
}
QString str = http->readAll();
textbrowser->setText(str);
}
MAIN.CPP
#include "klasa.h"
#include
int main(int a, char**b){
QApplication app(a,b);
GofunHelp m;
m.show();
return app.exec();
}