python + qt
-
hi again, forum!
i wanna write a program in c++ (using qt, of course) but for some part of the program i find python more efficient. how can i mix these 2 language codes?
(pyqt? i know about it, i'm just curious about this language mix version)
-
@user4592357
If you have decided that you want to write the Qt stuff in C++, you won't be using PyQt, and it becomes a question of how to call bits in Python from your C++ app? -
@JNBarchan
i know that i can't use pyqt in my c++ + qt app. i meant, i can just use pyqt. but no. i don't want that
and what is bits?
-
@user4592357
Are you expecting an answer that has anything to do with Qt? Or are you expecting an answer about how to call Python code from C++ code, or even C++ from Python? -
@JNBarchan
sorry, i didn't quite well mention that.
so, as i said the main app is in c++ and for gui i'm using qt, and i need to call python code from my c++ code. the python code will take some qt component as its argument and do its job based on that component data. i hope this is clear
-
@user4592357 said in python + qt:
the python code will take some qt component as its argument and do its job based on that component data.
Ah! Now you're saying you're going to write the UI/Qt side in C++, but you still want to pass Qt objects etc. on to Python code, and act on them there. But you don't want to use PyQt.
Then good luck! Because it seems to me PyQt is a great big library of code precisely to make Qt stuff accessible from Python. So if you're going to do that yourself, you'll want to reimplement all the code & ideas there for your purposes.
-
@user4592357
To summarise, from what you describe, I believe you have 4 choices. I see them in the following order of desirability/simplicity (best to worst):-
Stick to one language, either C++ or Python. If you do want to use Python, you can do anything at the Qt/UI side via PyQt which you could do "natively" via C++, so it is not obvious that C++ would be the only choice for Qt interface.
-
If you must mix languages, do everything to do with Qt/UI in your C++ side, and don't pass anything Qt to/from Python.
-
If you must mix languages and you have to have your Python side aware of the UI side, make an abstraction of the Qt stuff such that the C++ passes only what is relevant extracted from the Qt to Python, and similarly the Python can alter that intermediate layer and then the C++ turns it back into Qt calls. This means that no Qt objects/calls are passed across the languages.
-
Finally, your idea of mixing the two languages and passing Qt stuff around. I don't know what you will do about accessing Qt from the Python side, given that you don't have the logic of PyQt which handles Qt from Python.
That's my opinion!
-
-
what i was describing, fits your 3rd point more.
i would want to use c++ but for some part of the program, python does the job better than c++ that's why i also need python
but maybe 1st point is good too. only pyqt