NameError: name 'Qt' is not defined
-
Hello I am searching for circular imports in my code and I try to avoid them and debug the code but I face this error:
File "code.py", line 535, in __init__ sharedLayout.setAlignment(Qt.AlignTop | Qt.AlignLeft) NameError: name 'Qt' is not defined
I have imported PyQt5...What is this?
-
Hi,
If you did just:
import PyQt5
Then it won't be able to find the Qt namespace because you only made the PyQt5 namespace available.
-
Yes but if I write
from...import....
I get circular imports! What should I do?
-
Use the fully qualified name.
How do you create circular imports by using PyQt5 ?
-
This is what I am trying to find out. What is the command of what you are writing?
-
@john_hobbyist
Which circular imports where?You can do this from PyQt5:
from PyQt5.QtCore import Qt
and then your original code should work.
In fairness, it is a bit complicated. https://stackoverflow.com/questions/39316693/how-to-import-from-qt-namespase-qt5-python3-x, the solution there, describes the situation and why this works, if you care.
-
PyQt5.QtCore.Qt.Whatever
Or more simply:
from PyQt5.QtCore import Qt
and then use Qt.
-
Amazing! It works!!! Thanks a lot for your time!
-
@john_hobbyist said in NameError: name 'Qt' is not defined:
It works!!!
so please don't forget to mark your post as solved!