0

I am writing an application in Qt5, and I have used QtScript (script engine) to evaluate JavaScript. I want to create a transmission control protocol socket in one JavaScript file, and I want to use that function in another JavaScript.

For example, I'll write one JavaScript file:

function CreateSocketfunction()
{
//...... Logic for creating socket in java script
}

and another JavaScript file:

//calling function.
CreateSocket();

Does anyone know how to accomplish this task?

Tay2510
  • 5,748
  • 7
  • 39
  • 58
Prachi
  • 1
  • 2
  • Do you know how to add and use c++ classes in QtScript? You can just use QTcpSocket – Dávid Kaya Apr 15 '15 at 06:18
  • yes.. i can use QTcpsocket in qt app, but, i want to write the logic in js file(java script file), and java script does not support qt classes – Prachi Apr 15 '15 at 06:22
  • You can use [Q_SCRIPT_DECLARE_QMETAOBJECT(...)](http://doc.qt.io/qt-5/qscriptengine.html#Q_SCRIPT_DECLARE_QMETAOBJECT) to make the class available to QtScript engine – Dávid Kaya Apr 15 '15 at 06:27
  • ok, thnx for the answer. ill try it and let you know if it is working wel. hopefullt by using this, ill be able to access qt socket in java script, as the code will be written in java script only. – Prachi Apr 15 '15 at 06:44
  • thanx, its done... i have used wrapper class for QTcpSocket, and passed it to scripting. all function in wrapper class were marked as Q_Invokable... – Prachi Apr 23 '15 at 04:53

0 Answers0