Solved Enter the code via the widget
-
You mean something like http://doc.qt.io/qt-5/qjsengine.html?
-
But this for JavaScript. Me need C++. Me need change code from application and after run changed function
-
@Mikee I'd say without lot of effort, impossible.
But what do you really want to do?
-
I need to change the code of my app and re-calculate the arrays.
-
C++ is a compiled language so it's very hard to make it become an interpreted one.
-
Hi
Why do you need to change the code ?
Is it not possible to make the calculation dynamic so you can change parameters for how / what it calculates. ?
Often there would be no need to change the actual code. Just adjust parameters.
-
But it is possible to do this? I know that C#is possible.
-
First is the calculation of the arrays. Then you need to change the code calculations. Then for this code again, need to do the calculation.
-
@Mikee C++ is not C#. C++ does not have a virtual machine like .Net.
To do what you want to do you would need to provide compiler, linker, header files and all other stuff needed to build your app and its source code! Are you really sure you want to do this?! To me it is still unclear why users of your application need to change the code of your application?"First is the calculation of the arrays" - what arrays?
"Then you need to change the code calculations" - why?
Can you explain better and maybe show an example? -
Example program Wealth-Lab.
Arrays stock quotes.
So long as data read from a file, it is convenient to modify the code calculation, rather than restart the whole application.
C++ have .Net.
https://en.wikipedia.org/wiki/.NET_Framework -
@Mikee I still don't understand: who will use your app? Do you expect your users to be able to edit C++ code?
"So long as data read from a file, it is convenient to modify the code calculation, rather than restart the whole application" - I don't get it. What and why exactly do you want to modify?Yes, you can use C++ with .Net. But are you aware that you would need to stop your app, rebuild it and then start again? Neither C++ nor C# are interpreted languages - you need to build C#/C++ applications if you change the source code.
-
@Mikee Actually you are wrong: "Wealth-Lab has an integrated programming environment based on C# syntax" from here: https://en.wikipedia.org/wiki/Wealth_Lab
So, what they did is: they incorporated their own programming language which is close to C# and the code written with this programming language is INTERPRETED inside Wealth-Lab. The DON'T rebuild their app.
You can do similar things with http://doc.qt.io/qt-5/qtscript-index.html -
@Mikee
The simple answer is, what you're talking about in C# is not available for C++. Whatever dynamic code generation you were doing is not the approach you will take here. -
How can I add a compiler in QT or VS to the app?
How can I convert text "void A12(double q1) {qDebug()<<q1;}" in code? -
@Mikee
Well you can install a compiler and call it with QProcess.
But what you are trying will just work extremely poorly and unless
"void A12(double q1) {qDebug()<<q1;}" is compiled into a DLL and and your
main app can load that DLL at runtime and use the function,how are you planning to be able to run it ?
Such user runnable code additions is far better handled with an integrated script language
like
javascript
python
http://chaiscript.com
https://www.lua.org/Say you install a compiler with your app.
If you then compile the text file. You get an .O file.
And that cannot run.
You could add that to the main program and recompile it so it can use the function.
But that has to be from outside the program and it be a mess for any end users.
Also you would have to include all of the source code of your app.So WHY must it be c++ you insists on using as a scripting language?
It will be very complicated and how will you handle when there is compiling errors
because user typed invalid c++? -
@Mikee Why don't you simply use http://doc.qt.io/qt-5/qtscript-index.html ?
-
@Mikee said in Enter the code via the widget:
How can I convert text "void A12(double q1) {qDebug()<<q1;}" in code?
"void A12(double q1) {qDebug()<<q1;}" - this is already code. What you would need to do is: compile and link it into a binary.
But you should use http://doc.qt.io/qt-5/qtscript-index.html instead.
Your example, Wealth-Lab, is doing it in a similar way: it uses a SCRIPTING language similar to C# (it is NOT the normal C# from Microsoft!). So, Wealth-Lab does NOT compile C# code. -
I can use the library to solve problem. It is normal C++.
I created project library and write in .cppStrategyCod::StrategyCod() { qDebug()<<"text from library"; }
What to do with the project library?
What file to use to connect to the app? -