Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Accessing a PHP object from server.
QtWS25 Last Chance

Accessing a PHP object from server.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Olivier75009
    wrote on last edited by
    #1

    Hello all,

    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.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      Hi!

      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.

      Regards,
      Jake


      Code is poetry

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Olivier75009
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jake007
          wrote on last edited by
          #4

          No they cannot. XML, Json and similar notations are used for this.
          And besides, parsing print_r string is NOT reliable.

          Short sample why:
          @<?php
          $a = array( 0 => "15 [2] => 16");

          print_r($a); // prints out: Array ( [0] => 15 [2] => 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.

          Regards,
          Jake


          Code is poetry

          1 Reply Last reply
          0
          • O Offline
            O Offline
            Olivier75009
            wrote on last edited by
            #5

            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.

            Regards,
            Olivier

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jake007
              wrote on last edited by
              #6

              It's QDomDocument.
              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.


              Code is poetry

              1 Reply Last reply
              0
              • O Offline
                O Offline
                Olivier75009
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved