[SLOVED] qt 5.0.2 how to get the source of webpage ?
-
-
well ... you're not using QNam::get() as i stated. Also see the docs.
The error message is also pretty obvious - which already provides the solution... -
Can you write full example for me please?
because i am really new in qt network -
i think i already did ?!!
Just read the complete error message and compare my get() call with yours... if you don't see a difference ... well ... -
Where i should put
void onRequestFinished?
@
ui->setupUi(this);
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QPointer<QNetworkReply> reply;
reply = manager->get(QNetworkRequest(QUrl("http://qt-project.org")));
connect(reply, SIGNAL(finished()), this, SLOT(onRequestFinished()));
void onRequestFinished() {}
@
returns:
In constructor 'MainWindow::MainWindow(QWidget*)':
error: a function-definition is not allowed here before '{' token -
this is a slot... so it is a member method of your class.
And also the QPointer<QNetworkReply> object should be a member then to identify the reply in this slot.Hope this clears it up:
In your header file:
@
class MyClass : public ...
{
public:
MyClass();protected slots:
void onRequestFinished();protected:
QPointer<QNetworkReply> m_Reply;
}
@In your source file:
@
MyClass::MyClass()
{
m_Reply = nam->get( QNetworkRequest( QUrl("http://google.com") );
connect( reply, SIGNAL(finished()), this, SLOT(onRequestFinished()) );
}void MyClass::onRequestFinished()
{
if( ! m_Reply )
return;if( m_Reply->error() == QNetworkReply::NoError ) { QString sourceCode( m_Reply->readAll() ); ... } m_Reply->deleteLater();
}
@ -
I am completely lost
-
[quote author="ThElitEyeS" date="1372673232"]I am completely lost[/quote]
sorry..but so am i... if thats all you say.I'm not able to help you, except you tell me what exactly you don't understand.
The code i've posted is a complete example in usage of QNetworkAccessManager::get(), only your own code needs to be integrated into my code. -
Is that right ?
!http://s15.postimg.org/tkdarufvf/Screenshot_from_2013_07_02_23_00_40.png(image)!
*Also how i can check if reply is finished in console application and how i can qDebug the code ?
*if i try
@qDebug << code; it will give me a error@ -
i think i got it working.
thank you raven for the big help you showed :)
!http://s21.postimg.org/8l395k8av/Screenshot_from_2013_07_03_00_15_57.png(a)!