printing issue in a qt app pyqt5
-
Hello,
I am using the software Salome-platform which is a pyQT application. In Salome, there is an embedded python console, and when the program is open at the same time it opens a terminal window (not the python one i mentioned previously but the classic terminal). In the python embedded console one can run python scripts, and if the python script has print on it it will print the output in the python console which is the desired behavior. but In some cases, when I create an Qtdialog which runs a function when the dialog is accepted and in this function it has a print function inside of it, the print ouput instead of print in the python console it will print in the terminal windows that opened at the same time as salome window.
this is how it looks a small script where this behavior is happening (that the print output goes to the terminal windows instead of the python terminal inside the salome window as it classically does)from PyQt5.QtWidgets import QWidget, QMessageBox from PyQt5 import QtCore, QtGui import PyQt5.QtCore as QtCore from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt def testForPrint(a): print(a) # -> if testForPrint is run from okbox.connect this will print in the terminal windows instead if instead the function is called from the main body it will print in the python console print(a,flush=True) # -> this will print in the terminal windows instead return bal='the dialog was accepted' print(bal) #-> this will print correctly into the python console dialog = QDialog() okbox = QDialogButtonBox(dialog) okbox.setOrientation(QtCore.Qt.Horizontal) okbox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) okbox.setStyleSheet('QPushButton {font-weight: bold}') okbox.accepted.connect(lambda: testForPrint(bal)) okbox.accepted.connect(lambda: dialog.hide()) okbox.rejected.connect(lambda: dialog.hide()) dialog.show() dialog.raise_()
the structure of the script I need to keep it like this, as it is more complex and i need to wait until the testForPrint function is run to have the necessary data to print it. but would like that the print inside the function would be outputed to the python console instead of the terminal window. I know that this is pyqt related, as when I call the same function without calling it from the okbox button it will print correctly. would love some recommendations on how to solve this issue.
-
@otaolafr said in printing issue in a qt app pyqt5:
I am using the software Salome-platform
Shouldn't you ask them? I doubt anybody here knows the internals of that software.
-
@jsulm Hello!
Yes I asked in their forum, but sadly there is not a lot of users that are active in the forum. and this issue only rises when I use pyqt5 (not saying that there is something wrong with it, but simply that i am doing something wrong myself XD) i thougt that maybe with a little bit of luck someone had had the same kind of issue in another application...
regards