First Qt Python project
-
EDIT / UPDATE
OK, I am little familiar with uic process ( converting ui to py ), question remains HOW and WHERE to execute this "command" . As written is has to be done in folder where "from.ui" resides....
Does Qt has a simple way to accomplish this ?
I would not call running this "command" using terminal simple...
been there , done that running terminal command...is not simple process in Qt. ( of course your opinion will vary from mine , but that does not help solving the issuer.# Important: # You need to run the following command to generate the ui_form.py file # pyside6-uic form.ui -o ui_form.py, or # pyside2-uic form.ui -o ui_form.py
After adding push button "slot" -> clicked ` I get this,
"missing ui_form.h".All I did is add "main widget" with some widgets , and included plain "pushbutton" .
What is this missing "ui_form.h"?
Please - only constructive suggestion / solutions - no AI referral AKA "read Hello word ".
I am starting from scratch and expect (?) basic code to work.
Adding slots in C++ works , why it fails in Python?
PS
For the AI pedants here - rebuilding (the project) did not work , hence my post ...duh -
EDIT / UPDATE
OK, I am little familiar with uic process ( converting ui to py ), question remains HOW and WHERE to execute this "command" . As written is has to be done in folder where "from.ui" resides....
Does Qt has a simple way to accomplish this ?
I would not call running this "command" using terminal simple...
been there , done that running terminal command...is not simple process in Qt. ( of course your opinion will vary from mine , but that does not help solving the issuer.# Important: # You need to run the following command to generate the ui_form.py file # pyside6-uic form.ui -o ui_form.py, or # pyside2-uic form.ui -o ui_form.py
After adding push button "slot" -> clicked ` I get this,
"missing ui_form.h".All I did is add "main widget" with some widgets , and included plain "pushbutton" .
What is this missing "ui_form.h"?
Please - only constructive suggestion / solutions - no AI referral AKA "read Hello word ".
I am starting from scratch and expect (?) basic code to work.
Adding slots in C++ works , why it fails in Python?
PS
For the AI pedants here - rebuilding (the project) did not work , hence my post ...duh@AnneRanch are you using visual code? run the pyside6-uic form.ui -o ui_form.py in the terminal bar at the bottom.
or you can just use the file in a program like such:import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QVBoxLayout, QWidget, QFormLayout, QLineEdit, QHBoxLayout from PyQt5.uic import loadUi class MyWidget(QMainWindow): def __init__(self): super().__init__() # Load the .ui file loadUi('example.ui', self) # Connect the button click event to the function self.pushButton.clicked.connect(self.on_button_click) def on_button_click(self): # Get the text from the line edit and set it to the label text = self.lineEdit.text() self.label.setText(f"Hello, {text}!") if __name__ == '__main__': app = QApplication(sys.argv) window = MyWidget() window.show() sys.exit(app.exec_())
-
EDIT / UPDATE
OK, I am little familiar with uic process ( converting ui to py ), question remains HOW and WHERE to execute this "command" . As written is has to be done in folder where "from.ui" resides....
Does Qt has a simple way to accomplish this ?
I would not call running this "command" using terminal simple...
been there , done that running terminal command...is not simple process in Qt. ( of course your opinion will vary from mine , but that does not help solving the issuer.# Important: # You need to run the following command to generate the ui_form.py file # pyside6-uic form.ui -o ui_form.py, or # pyside2-uic form.ui -o ui_form.py
After adding push button "slot" -> clicked ` I get this,
"missing ui_form.h".All I did is add "main widget" with some widgets , and included plain "pushbutton" .
What is this missing "ui_form.h"?
Please - only constructive suggestion / solutions - no AI referral AKA "read Hello word ".
I am starting from scratch and expect (?) basic code to work.
Adding slots in C++ works , why it fails in Python?
PS
For the AI pedants here - rebuilding (the project) did not work , hence my post ...duh@AnneRanch
Purely a guess. Qt Creator's Designer does not know you are programming for Python, it assumes you are going to use C++. If you try to add a slot to a signal in Designer it errors when it cannot find the C++.h
header file.May not be the case, but if it is don't use the signal/slot support from Designer, connect your signals to slots in Python code.
-
@AnneRanch
Purely a guess. Qt Creator's Designer does not know you are programming for Python, it assumes you are going to use C++. If you try to add a slot to a signal in Designer it errors when it cannot find the C++.h
header file.May not be the case, but if it is don't use the signal/slot support from Designer, connect your signals to slots in Python code.
@JonB Bad guess... I did follow the "new program" and usied "Python" option. Easy to verify - it builds "python project" .
If I can add to your guess - my is guess is - Qt is not doing full job on building the python code.
I am still looking for reasonable tutorial for "how to build python app using QtCreator".
All I have seen so far is not using QtCreator.
But another guess - from very limited experience with Python code -
there is NO need for "python project" - that is an add of QtCreator and not what I expected , NOT "ready to run".Cheers
-
@AnneRanch are you using visual code? run the pyside6-uic form.ui -o ui_form.py in the terminal bar at the bottom.
or you can just use the file in a program like such:import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QVBoxLayout, QWidget, QFormLayout, QLineEdit, QHBoxLayout from PyQt5.uic import loadUi class MyWidget(QMainWindow): def __init__(self): super().__init__() # Load the .ui file loadUi('example.ui', self) # Connect the button click event to the function self.pushButton.clicked.connect(self.on_button_click) def on_button_click(self): # Get the text from the line edit and set it to the label text = self.lineEdit.text() self.label.setText(f"Hello, {text}!") if __name__ == '__main__': app = QApplication(sys.argv) window = MyWidget() window.show() sys.exit(app.exec_())
@MIckH Thanks, but that is exactly what I am trying to avoid - building the GUI code by myself - have QtDesigner to do the dirty work .
( I have already tried and it was a pain...)I always had an issues understanding the QtDesigner / QtCreator GUI - how it builds .ui file and then the "header.ui" in C++.
Now I have even more complicated issue with Python doing same.No, I am using "plain" QtCreator.
I am going to build fake header ui and see it I can fool the error... -
@JonB Bad guess... I did follow the "new program" and usied "Python" option. Easy to verify - it builds "python project" .
If I can add to your guess - my is guess is - Qt is not doing full job on building the python code.
I am still looking for reasonable tutorial for "how to build python app using QtCreator".
All I have seen so far is not using QtCreator.
But another guess - from very limited experience with Python code -
there is NO need for "python project" - that is an add of QtCreator and not what I expected , NOT "ready to run".Cheers
-
@JonB Yes, I am trying to learn / build a simple project and that is only GUI I have added .
BTW
I added the "missing file" , it shows in "python project" , but it is still missing... -
@JonB Yes, I am trying to learn / build a simple project and that is only GUI I have added .
BTW
I added the "missing file" , it shows in "python project" , but it is still missing... -
EDIT / UPDATE
OK, I am little familiar with uic process ( converting ui to py ), question remains HOW and WHERE to execute this "command" . As written is has to be done in folder where "from.ui" resides....
Does Qt has a simple way to accomplish this ?
I would not call running this "command" using terminal simple...
been there , done that running terminal command...is not simple process in Qt. ( of course your opinion will vary from mine , but that does not help solving the issuer.# Important: # You need to run the following command to generate the ui_form.py file # pyside6-uic form.ui -o ui_form.py, or # pyside2-uic form.ui -o ui_form.py
After adding push button "slot" -> clicked ` I get this,
"missing ui_form.h".All I did is add "main widget" with some widgets , and included plain "pushbutton" .
What is this missing "ui_form.h"?
Please - only constructive suggestion / solutions - no AI referral AKA "read Hello word ".
I am starting from scratch and expect (?) basic code to work.
Adding slots in C++ works , why it fails in Python?
PS
For the AI pedants here - rebuilding (the project) did not work , hence my post ...duh@AnneRanch I'm pretty sure this is an issue of Qt Designer/Qt Creator not having the python support needed for this feature, but I'm not 100% sure.
The basic Qt for Python examples provided definitely work, and there is some basic support for Qt for Python in Qt Creator (syntax highlighting, creating "project" files, and a few others), but Qt Creator support for Python certainly could use some work.
@CristianMaureira - is there support for this feature with Qt for Python apps in Qt Designer?
To clarify: Qt Designer is the visual component designer piece of Qt Creator. Qt Creator is the larger app that allows you to create new projects, add new files, edit code, build, etc. Qt Creator has basic support for Python. The question is - does the designer piece have python support? Based on your experiences, it sounds like it doesn't.
-
@AnneRanch I'm pretty sure this is an issue of Qt Designer/Qt Creator not having the python support needed for this feature, but I'm not 100% sure.
The basic Qt for Python examples provided definitely work, and there is some basic support for Qt for Python in Qt Creator (syntax highlighting, creating "project" files, and a few others), but Qt Creator support for Python certainly could use some work.
@CristianMaureira - is there support for this feature with Qt for Python apps in Qt Designer?
To clarify: Qt Designer is the visual component designer piece of Qt Creator. Qt Creator is the larger app that allows you to create new projects, add new files, edit code, build, etc. Qt Creator has basic support for Python. The question is - does the designer piece have python support? Based on your experiences, it sounds like it doesn't.
@AnneRanch
To be clear: Designer should have no support, either for C++ or for Python. It's only job is to create a.ui
file (which is XML) describing the elements designed. Then- For C++ you run
uic
to pre-process the.ui
to produce aui_....h
file. That should then be#include
d into one of your source C++ files. - For Python you run
pyside6-uic
/uic -python
or equivalent to pre-process the.ui
to produce aui_....py
file. That should then beimport
ed into one of your source Python files.
The error message you show comes from Creator. In some shape or form it is trying to access the generated
ui_....h
file to find or add a slot for the pushbutton selected in Designer. But since you are Python not C++ it's not going to find it. Why Creator is doing this in response to whatever you did I do not know.You are not alone in this. https://www.qtcentre.org/threads/71236-Python-QT5-Creator, for example, reports exactly the same from Python when
If you go to form.ui and try to add a clicked slot to the button clicked(), an error appears that the "could not find documents matching ui-form.h / Perhaps rebuilding will help"
with no resolution. And just the same in https://stackoverflow.com/questions/65605978/python-qtcreator-and-slots.
So if this is so, and it's not some misconfiguration for Python in Creator/your project, then as I said I suggest it's a bug, and you will have not to try to access slot code from Creator/Designer.
- For C++ you run
-
@AnneRanch
To be clear: Designer should have no support, either for C++ or for Python. It's only job is to create a.ui
file (which is XML) describing the elements designed. Then- For C++ you run
uic
to pre-process the.ui
to produce aui_....h
file. That should then be#include
d into one of your source C++ files. - For Python you run
pyside6-uic
/uic -python
or equivalent to pre-process the.ui
to produce aui_....py
file. That should then beimport
ed into one of your source Python files.
The error message you show comes from Creator. In some shape or form it is trying to access the generated
ui_....h
file to find or add a slot for the pushbutton selected in Designer. But since you are Python not C++ it's not going to find it. Why Creator is doing this in response to whatever you did I do not know.You are not alone in this. https://www.qtcentre.org/threads/71236-Python-QT5-Creator, for example, reports exactly the same from Python when
If you go to form.ui and try to add a clicked slot to the button clicked(), an error appears that the "could not find documents matching ui-form.h / Perhaps rebuilding will help"
with no resolution. And just the same in https://stackoverflow.com/questions/65605978/python-qtcreator-and-slots.
So if this is so, and it's not some misconfiguration for Python in Creator/your project, then as I said I suggest it's a bug, and you will have not to try to access slot code from Creator/Designer.
@JonB , just one small correction - starting from Qt 6.x you don't have
pyside-uic
anymore - you should use pureuic
for both C++ and Python. But for python you should run it asuic -g python
(actually we already explained it to @AnneRanch in parallel thread about external tools in PyCharm).With regards to Qt Designer and Python usage together - here is an article - it is a bit outdated but gives a sense of the context.
- For C++ you run
-
@kkyzivat
POSTED BEFORE reading most recent responses.
Since majority of "arguments" are mostly differences of opinions , thus seldom based on facts - here is an exception - my opinion based on facts. I can access Qt Python options (fact) and run "Python project" (fact) and I expect it to work. If it does not work (fact)- Qt vendor should remove Python option (opinion) . -
@kkyzivat
POSTED BEFORE reading most recent responses.
Since majority of "arguments" are mostly differences of opinions , thus seldom based on facts - here is an exception - my opinion based on facts. I can access Qt Python options (fact) and run "Python project" (fact) and I expect it to work. If it does not work (fact)- Qt vendor should remove Python option (opinion) .@AnneRanch ...and after reading the last few posts ... this is getting off the subject (finding a solution ) and if there are no objections - PLEASE consider this thread closed.
My , hopefully temporary conclusion, is -
Qt Creator is not what one would use to build his /hers first Python project - caveat emptor . -
@JonB , just one small correction - starting from Qt 6.x you don't have
pyside-uic
anymore - you should use pureuic
for both C++ and Python. But for python you should run it asuic -g python
(actually we already explained it to @AnneRanch in parallel thread about external tools in PyCharm).With regards to Qt Designer and Python usage together - here is an article - it is a bit outdated but gives a sense of the context.
@StarterKit Sorry if it was not clear with all the release messages.
pyside6-uic
is still the recommended tool, because it uses theuic
binary we include in the wheel. Encouraging people to useuic
will cause problems because they might have another version installed in the system. -
@AnneRanch ...and after reading the last few posts ... this is getting off the subject (finding a solution ) and if there are no objections - PLEASE consider this thread closed.
My , hopefully temporary conclusion, is -
Qt Creator is not what one would use to build his /hers first Python project - caveat emptor .@AnneRanch this has been a long standing issue, mainly on how we can connect the designer capabilities with Python, at the moment with newer QtCreator versions, when you press "run" we run
pyside6-project
which detects any.ui
file and runspyside6-uic
on them, and the same with.qrc
files andpyside6-rcc
so people don't need to worry about it.The good thing is that in the last couple of days there was an agreement between QtCreator and Qt for Python PMs to create a roadmap to get a full support in QtCreator.
You are completely right that if you open a Python project, and you click any button or select any option things should work, the problematic bit is that QtCreator is an IDE that was not built with the use cases of other languages, so we need to work hard on trying to see how we can massage the current options for Python users.
Even the main concept of "a kit" is somehow not needed for Python users, but they still need to work around to get that configuration with some values that make sense.I cannot tell you @AnneRanch what would be the future options, or use-cases, because it's something that's being defined. There has been lots of improvements in QtCreator since Qt for Python was released, and connecting more functionalities with Designer is still an open one.
Because you are currently using, I'd encourage you to help the project by filing as many bugs as you encounter, because we are not considering all uses cases, mainly to have a bias developer point of view.Hopefully we can address the go-to-slot issue, which was raised some time ago by another user and we haven't managed to figure out :)
-
I do appreciate you taking time for reply.
However, you may not be aware that what I was trying to do is not
“normal”. As a user of C++ QtCreator /QtDesiger I did expected that I can modify existing Python application using QtDesigner. That just did not work and it is not a “big deal” ( to me) that it does not.There are other Qt issues which could use some attention and hopefully a resolution.
However, I feel this is is not the place to discuss that, and most of them have been “reported” as bug(s) anyway.