Accessing a PHP object from server.
I'm trying to get an object returned by a method from a PHP script, using QtNetworkAccessManager. When returning object, I can't read a byte (0) as it's still an object. But print_r this object returns me the complete object through a string, than I do not want.
Is there any way to catch a returned PHP object with Qt and how could I access attributes/values from this object ?
Thanks for reading me.
You'll need to serialize data on both ends, so it's readable. I would recommend XML (built in) or JSon ( requires external library). So you convert your data to xml string, fetch it with Qt and then parse it.
You probably won't be happy with a solution, but this is how it goes.
You can always write your own parser for string types that print_r returns.
I was thinking about parsing a xml file. I tried to serialize the object from the server but it added lots of unnecessary attributes. I think I would rather get it in xml (if I really can't access a returned object from PHP) than applying QString manipulations over a print_r. It would be probably simpler from PHP then accessing it when parsing onto Qt.
I'm asking from a solution from accessing an object from the server as I can not imagine that a POO scripting and Qt (C++ as POO) can not communicate together. Maybe I'm wrong and I would like it to be confirmed.
Thanks a lot for your answer.
NB : Actually, I heard from QtSoap and I did not read anything about it yet. I acceded the method when writing a new php script waiting from $_POST and redirecting to the method, whereas I acceded to a class method directly from a program written in AS3 via Zend Framework before I had to rewrite all my soft' in C++. QtSoap seems to be able to access directly to the method.
No they cannot. XML, Json and similar notations are used for this.
And besides, parsing print_r string is NOT reliable.
Short sample why:
$a = array( 0 => "15  => 16");
print_r($a); // prints out: Array (  => 15  => 16 )
In upper example, you have an array with 1 element, but when parsing you'd get 2. It's extremely small chance that that would happen. If users are involved, use 100% option not just 99.999...%
And I cannot help you with soap, as I do not know it.
Thank you Jake. I echoed a xml file instead of returning my php object. I now can read it, but searching for the best way to convert it into a QObject. I read than QDomObject or something would be the way to.
Take a look at "this tutorials":http://www.voidrealms.com/tutorials.aspx?filter=qt. ( search for xml)
How do you mean to convert it to QObject?
You'll have to parse and set each variable in class. This is in case where your object structure is always the same.
Or if you have dynamic structure, you'll have to use a little more complex method. Class which has only a list of property name and value. You could try using models. But it isn't the most simple thing.
I want to access an object as in PHP, AS3 or other script OO models.
I have identical structures from some objects, so I'll probably have to create classes for those objects first, then extract values from my xml files after getting them into a QDomDocument.