I’m trying to communicate an external python script with a C++ program that allows qt-scripting. The goal its to partially control the C++ program (using its qtscript api functions) from python code.
I know how to create a basic socket server/client in python:
#Server code import socket server = socket.socket() server.bind (("localhost", 8080)) server.listen(10) client, client_adress = server.accept() while True: message= cliente.recv(1024) if message== "quit": break print "Received:", message client.send(message) print "Goodby" cliente.close() server.close()
#client code import socket client = socket.socket() client.connect(("localhost", 8080)) while True: message = raw_input(">" ) client.send(message) if message == "quit": break print "Goodby"
There is this question, but it was not useful to my problem. And there is this samples but I can’t make it work.
Whats is better, the client or the server in Python?
Could I can find a qtscript example?
This way the Python side is quite trivial. For the C++ side, you’d first create a
QTcpServer and then when it receives data, read all of it and pass the string to
QScriptEngine::evaluate(). For how to use
QTcpServer, see here: http://doc.qt.io/qt-5/qtnetwork-fortuneserver-example.html
Answered By – John Zwinck
Answer Checked By – Mary Flores (BugsFixing Volunteer)