Unsolved How to get/parse pastepin raw content using qt5 ?
-
How do i get/parse pastepin raw content using qt5 then do whatever with it?
example url: http://pastebin.com/raw.php?i=CNT3Kz2H
PS. i need somthing very simple and console only no need for gui.
-
You need to be a little more specific than that.
You can get content from the web via QNetworkAccessManager.
What do you mean by parse? Into what? And what do you want to do with it? "Whatever" can mean anything and there's no one way to do "anything" ;) -
@Chris-Kawa , i want to be able to parse the content into a Qstring , the example below is not working : ( PS. i need somthing very simple and console only no need for gui.)
class MyClass : public QObject { Q_OBJECT public: MyClass(); void fetch(); public slots: void replyFinished(QNetworkReply*); private: QNetworkAccessManager* m_manager; }; MyClass::MyClass() { m_manager = new QNetworkAccessManager(this); connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); } void MyClass::fetch() { m_manager->get(QNetworkRequest(QUrl("http://stackoverflow.com"))); } void MyClass::replyFinished(QNetworkReply* pReply) { QByteArray data=pReply->readAll(); QString str(data); //process str any way you like! }
-
Oh, ok. So just for the record - that's not parsing. Parsing is a process of analyzing some input and transforming it into another form. what you seem to want is just fetching some data.
The code you posted looks ok. For networking and signal/slot connections to work you need a running event loop (
exec()
). I'm assuming you don't have one as this is common mistake when writing a console app.
Can you show your main() ?Btw. please surround code with ```, not html tags.
-
@Hanoosh
Hi
Your code does work.
please try
https://www.dropbox.com/s/9gkycyliz0h6cyp/netreader.zip?dl=0 -
@mrjj Thanks it works, is there anyway to make it simpler like in only one .cpp file with no header file?
-
@Hanoosh
Hi
no. there must be .h file.
the tool that make signal and slot works, called moc.exe, only reads .h files.
So class MyClass : public QObject must be in a .h file. -
Hi,
In fact yes, it's possible, you have to include the moc file at the end of the .cpp file to force moc to parse the .cpp file. It's used for Qt's unit tests. Note that it's not the usual way to do it. @mrjj's solution is the good clean classic.
-
@mrjj Thanks for the info and help, how to make it support ssl link?
-
@Hanoosh
Hi
Do you mean HTTPS ? -
@mrjj yes, thanks
im getting this with https link:
QSslSocket: cannot call unresolved function SSL_CTX_new QSslSocket: cannot call unresolved function SSL_library_init QSslSocket: cannot call unresolved function ERR_get_error
-
@Hanoosh
I think you need to set something with QSslConfiguration
and install OpenSSL binaries
https://forum.qt.io/topic/9376/solved-qnetworkaccessmanager-https-code-2-error-qnetworkreply-remotehostclosederror
(code in top)
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());for binaries
http://slproweb.com/products/Win32OpenSSL.htmlThis is purely guessing so you might want to wait to see if someone knows exactly.
.
-
@mrjj Thanks, i've found the code below and i'm trying to implement in my code:
QNetworkAccessManager qnam; QSslConfiguration sslConfiguration(QSslConfiguration::defaultConfiguration()); SslConfiguration.setProtocol(QSsl::SslV3); QNetworkRequest req; req.setSslConfiguration(sslConfiguration); req.setUrl(QUrl("https://www.address.tld/")); QNetworkReply *rep = qnam->get(req);