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. How to connect to a server from Qt C++ and QML?
Forum Updated to NodeBB v4.3 + New Features

How to connect to a server from Qt C++ and QML?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 3.7k Views 1 Watching
  • 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
    Muhammad
    wrote on last edited by
    #1

    I have a Qt app that works in Desktop and android. When I was developing the app I refereed to some photos by their absolute path on my computer in both C++ and QMl, everything worked just fine.

    Now I'm deploying on android, I setup IIS on my computer and I put all the files I want the application to get from my computer on the same folder where IIS starts (the "wwwroot").

    A friend of mine gave me some php files to put them in the same directory where IIs starts to allow the connection. I changed the paths to the files on my C++ and Qml codes to connect to the new path through the server. here is an example for the paths before and after:

    in C++
    before
    @QString path("E:/project/Server/Labs/");@

    after
    @QString path("http://192.168.173.1/Server/Labs/");@

    in Qml
    before
    @source: 'file:///E:/project/Server/Labs/image.jpg'@

    after
    @source: 'http://192.168.173.1/Server/Labs/image.jpg'@

    Now I'm able to get the files in qml successfully, but not the files in the C++ part. I can't connect to the folders and files in the server through C++.
    So is there something I should do in the C++ part?
    -Note: On Desktop when I leave the paths in qml to
    @source: 'http://192.168.173.1/Server/Labs/image.jpg'@

    they don't work and I get these errors
    @QSslSocket: cannot resolve TLSv1_1_client_method
    QSslSocket: cannot resolve TLSv1_2_client_method
    QSslSocket: cannot resolve TLSv1_1_server_method
    QSslSocket: cannot resolve TLSv1_2_server_method@

    So I have to change the paths back to
    @source: 'file:///E:/project/Server/Labs/image.jpg'@

    in order to work on desktop.
    Thank you.

    I don't have endpoint, I just have Checkpoints.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      In C++ you try to see a directory content and QML you are getting a file.
      Is it right?

      Does IIS allow to see the directory content?
      What do you see if you try to access http://192.168.173.1/Server/Labs/ from a web browser?

      When you try to get files in C++ do you check for the response return status?
      Are there any errors there?

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

        [quote author="andreyc" date="1404620323"]In C++ you try to see a directory content and QML you are getting a file.
        Is it right?

        Does IIS allow to see the directory content?
        What do you see if you try to access http://192.168.173.1/Server/Labs/ from a web browser?

        When you try to get files in C++ do you check for the response return status?
        Are there any errors there?[/quote]

        • In C++ I creat a @QDir@

        Instance and I give it the path
        @QString path("http://192.168.173.1/Server/Labs/");@

        and then I use @QDir::entryList(); @

        to get the files names in that directory.
        As I said that works just fine if the path is
        @QString path("http://192.168.173.1/Server/Labs/");@

        but not otherwise.

        • In Qml I'm specifying the path to image source, yes its a file.

        • At first I wasn't able to see the directories from the browser, but as I mentioned in the post a friend of mine gave me some php files I put them in the (C:\inetpub\wwwroot) directory and now I'm able to see all the files and directories in the ( http://192.168.173.1/Server/Labs/) if I write it in my browser in my computer or in the browser of my android which is connected to my computer through a local network.

        • I don't know how to check the response in C++, but I did checked if
          @QDir::entryList().isEmpty();@

        and it was always empty when I use the "http://192.168.173.1/Server/Labs/" in the path, but it wan't empty using "E:/project/Server/Labs/".

        I don't have endpoint, I just have Checkpoints.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Qt will not understand the IP address in String argument. It is cosidered as network path. QDir etc will not accept network path. Try using QNetworkAccessManager class to get individual images etc.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Muhammad
            wrote on last edited by
            #5

            [quote author="Dheerendra" date="1404650926"]Qt will not understand the IP address in String argument. It is cosidered as network path. QDir etc will not accept network path. Try using QNetworkAccessManager class to get individual images etc.[/quote]

            Aren't there any way that allows me to get information about all the files in a directory through network, because I don't want to get the files in the C++ side I just want to collect some information about them like their names and how many files in a specific directory and then I will get the files from the qml which seems to work well.

            I don't have endpoint, I just have Checkpoints.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #6

              To collect info about the files through the network in C++ you need to use "Qt Network":http://qt-project.org/doc/qt-5/qtnetwork-index.html module.

              See "a simple HTTP client":http://qt-project.org/doc/qt-5/qtnetwork-http-example.html example.

              All "network examples":http://qt-project.org/doc/qt-5/examples-network.html

              QML "supports network transparency":http://qt-project.org/doc/qt-5/qtqml-documents-networktransparency.html that is why you were able to switch the network easily with QML.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ikyb
                wrote on last edited by
                #7

                Links outdated. New updated links have new prefix: https://doc.qt.io/qt-5/........

                https://doc.qt.io/qt-5/qtqml-documents-networktransparency.html

                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