Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How can I send Http request from QML?
QtWS25 Last Chance

How can I send Http request from QML?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 13.4k 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.
  • M Offline
    M Offline
    mismail
    wrote on last edited by
    #1

    Hi all,

    I want to send http request to a server http://www.xxxxxxxxx.com/test/test.php

    with the following parameters
    name
    email
    message

    how can I do that in Qml?

    thank you for your help

    1 Reply Last reply
    1
    • I Offline
      I Offline
      Iktwo
      wrote on last edited by
      #2

      I'm almost sure that you have to use Qt for that, design you UI with QML and implement a method with Qt (using QNetwork module), then all the method from Qt, you can read about this in

      http://doc.qt.nokia.com/4.7-snapshot/qml-extending-tutorial-index.html
      http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html

      Edit:
      Basically you write a class that hinherits from QDeclarativeView, then you create an QDeclarativeContext and then you send the whole class to QML with

      @context->setContextProperty("Main", this);@

      then in QML you can do

      Main.method()

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mismail
        wrote on last edited by
        #3

        Ok, thank you.
        I will try

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          Hi,

          From within QML you can use "XMLHttpRequest":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeglobalobject.html#xmlhttprequest to make network requests.

          Regards,
          Michael

          1 Reply Last reply
          0
          • C Offline
            C Offline
            charlycoste
            wrote on last edited by charlycoste
            #5

            You can use the XMLHttpRequest (sorry @mbrasser , your link is outdated) which implements the W3C XMLHttpRequest API

            So, all you need to do is:

            var req = new XMLHttpRequest();
            req.open("POST", "http://www.xxxxxxxxx.com/test/test.php");
            req.onreadystatechange = function() {
              if (req.readyState == XMLHttpRequest.DONE) {
                // what you want to be done when request is successfull
              }
            }
            req.onerror = function(){
              // what you want to be done when request failed
            }
            

            Then when you want to send a request, just call :

            req.send("name=xxx&email=xxx&message=xxx");
            

            "It's not because things are difficult that we dare not venture. It's because we dare not venture that they are difficult." - Lucius Annaeus Seneca

            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