Solved How can I get things from website
-
-
@victor-wang You should print out reply->error()
If everything was fine then it should print out 0 (QNetworkReply::NoError) -
@jsulm
It shows no error.
That means everything was fine.
But why still have nothing?
Is there any possible because i receive a file? -
@victor-wang Is that out variable a QByteArray?
Also, what exactly does qDebug()<<out print out? -
-
@victor-wang can you do qDebug()<<out.size();?
-
-
@victor-wang said in How can I get things from website:
If it is how can i judge the signal and where do i have to add the function in?
You make a signal-slot connection, using
QObject::connect()
. When the signal is emitted, the connected slot will run automatically.This is a core feature of Qt. I recommend you spend some time to do tutorials to understand how to use signals and slots.
For the first of debugging and testing.
I will get this on my browser. hereOK, good. That means the server will give you text data.
For the second one, i'm not quite sure what does that mean.
Your code has
QUrl("http://192.168.100/59/...")
. Change this toQUrl("http://lists.qt-project.org/mailman/listinfo")
for testing.For third one, what does"QNetworkRequest constructly correctly"mean?
I thought i am using the library that Qt have already constructed.When you call
QNetworkRequest(QUrl(...));
you are constructing a QNetworkRequest.Let's check that your QNetworkReply is what you expect. Put this in your
replyFinished()
slot:qDebug() << reply->isFinished(); qDebug() << reply->error(); qDebug() << reply->request(); qDebug() << reply->url(); qDebug() << reply->rawHeaderPair();
For forth one, I'm sure i am on the same subnet because i can send this commend to my console
wget http://192.168.100.59/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF
And i will get the file and the content will show "updated ok".
OK, good.
-
for your Xming copy/paste problem to windows, take a look to this topic:
https://superuser.com/questions/440128/xming-clipboard-only-works-one-way
That should enable you to poste your code as text for us and not as pictures.
-
-
-
@victor-wang said in How can I get things from website:
@JKSH
I have try to get from the Url which you gave me for test.
And i will get this information here.So is that mean the code is not wrong?
Yes, your code is working correctly. Go to http://lists.qt-project.org/mailman/listinfo using your browser and view that web page's source (Ctrl+U in Google Chrome) -- it's the same as your last screenshot.
Your code is not wrong. Your device (192.168.100.59) probably returns data in a different way. Fix the errors below to investigate.
@victor-wang said in How can I get things from website:
@JKSH
I add the qDebug in the replyFiniched() slot but i got some errors.
HereOops, sorry... QNetworkRequest can't be printed through qDebug(). Just delete this line:
qDebug() << reply->request();
The other one should be
rawHeaderPairs()
, not rawHeaderPair() -
-
@victor-wang said in How can I get things from website:
I had change the Url back to the original one.
And i get thisIs that mean i had receive something?
Yes.
If it is why i didn't see any file that should get from the Url?
Because your code contains the wrong URL. You want LSN=201503003009, right?
-
@JKSH
Actually, if i connect success the URl i set will have the record.
But i just check it, there is nothing on it.
I don't know what to do now. -
@JKSH
I solved the problem!
I 'm too stupid that i type the wrong vocabulary.
It's Empid not Empld in the Url.
Thank you so much for all your help! -
@JKSH
There is another questions.manager->get(QNetworkRequest(QUrl(http://www1.winmate/PLMS/TestCheck.asp?LSN=201503003009&Empid=we9999&CPID=OS&CPKey=95Z0000000AF)));
what if the Empid is not the static one.
It will let the guest type there own id.
If i want to doing that how can i do it?Can i type like this?
manager->get(QNetworkRequest(QUrl("http://www1.winmate/PLMS/TestCheck.asp?LSN=201503003009&"+"Empid="+ID"&CPID=OS&CPKey=95Z0000000AF")));
-
@victor-wang You can do it like this (Empid= can be just part of the first string - no need for +"Empid=").
Take a look at http://doc.qt.io/qt-5/qstring.html#arg -
@jsulm @JKSH
I've got another question!
I have 10 different Url wanna connect and get information down.
And i'm using for() to do it.Here is my code.But it will crash and will not connect to the server.
I assume that it because for() is doing too quick.
So i add this inside the casereply->isFinished();
But it will crash in the beginning.
What else method can i try or what to fix in my code?
Do i need to add the switch case into replyfinished() slot instead of connect?Please help!
-
@victor-wang The problem isn't that for loop is too fast (how could it be too fast?).
Starting with case one you have:reply->isFinished();
How do you initialize reply? Most probably it is not initialized and you're dereferencing dangling pointer.
Second question: why do you call isFinished() on reply? isFinished() is a getter method which you can use to check whether the reply is finished or not. But you do not use its return value, so the call is completely useless.
In general: if your app is crashing you should first debug it before asking in a forum.
So, please remove that useless reply->isFinished(); and debug your code to see where exactly it is crashing and why.