need help to translate python script to Qt quick qml code



  • Hi, I am wondering if somebody could help me to translate py- code to Qt qml code because i have one code script in py and one in qml.

    The py code looks like this

    from socket import *
    
    HOST = ''
    PORT = 8001
    ADDR = (HOST, PORT)
    
    serversock = socket(AF_INET, SOCK_STREAM)
    serversock.bind(ADDR)
    serversock.listen(2)
    
    
    while 1:
        print("Wait for connection")
        clientsock, addr = serversock.accept()
        print('Connected from' + str(addr))
        while 1:
            data = clientsock.recv(2048)    
            print(data)
        
    serversock.close()
    

    and i wont to translate it and use 'data' variable as angle in my ui in qml. please help me.


  • Moderators

    Hi @antemort,
    It can't be done purely in QML. You will need to use sockets on C++ side. Qt has C++ API's for sockets. QTcpServer creates a server and QTcpSocket for client. After that you will need to expose them to QML.
    Edit: Some one has tried to do that already. See https://github.com/jemc/qml-sockets


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.