I am having a problem using the common dialog in PyQT. For some reason, when I try and import 'QFileDialog', I get a not found error, same with importing QDialog. I am on Py 2.7 (was 2.6) using 'PyQt-Py2.7-x86-gpl-4.8.2-1'. I can import QTCore and QTGui just fine. I thought PyQT4 exposed the QT Dialog class? It also doesn't seem to be part of the QTGui module either, even though the Class reference says it is.

I am using it as:

filename=QFileDialog.getOpenFileName("", "*.dbf", self, "FileDialog")

Error:

NameError: global name 'QFileDialog' is not defined

Recommended Answers

All 11 Replies

you need to add the sys path of pyqt to python 2.7 sys path .
Because py2.6 syspath in not the same as 2.7 syspath.(syspath is where your python got its modules and other modules installed/saved)

import sys
sys.path.append("pyqt path")## And you are set to jam!

Are you taking about 'C:\Python27\Lib\site-packages\PyQt4'?, or do I need to point at the BIN folder?

Nope.. using:
sys.path.append('C:\Python27\Lib\site-packages\PyQt4\')
or
sys.path.append('C:\Python27\Lib\site-packages\PyQt4\bin\')
or
sys.path.append('C:\\Python27\\Lib\\site-packages\\PyQt4\\')
or
sys.path.append('C:/Python27/Lib/site-packages/PyQt4/')

all compile fine, but I still get the error.. :(

Check if there is a pyqt for py2.7.
go to pyqt and look for py2.7 compability version. matbe the version is not supported on py2.7 ok.?

This is the PyQT version for 2.7 => "'PyQt-Py2.7-x86-gpl-4.8.2-1'", this is what I have installed. Like I said, QTCore and QTGui import fine, I just can't seem to get "QFileDialog" to be recognized. Even in my editor (JetBrains PyCharm), 'QFileDialog' is not listed as a member of QTGui as staed in the PyQT4 Bindings reference.

It's pretty frustrating as common dialogs are something used all the time. Thanks so much for your help though, even Google doesn't seem to have an answer.. ugh.. :)

The other frsutrating thing is that if I use the Interpreter to import the classes;

>>> from PyQt4 import QtCore,QtGui

then using Dir(QtGui) 'does' show QfileDailog as a member. I'm SURE it's because I'm not declaring something right.. Help!.. :)

Ok that means PYQT works and import fine but calling QFileDialog provides error. right?
Then i guess you need to look through QT docs about QFileDialog. ;)

It also doesn't seem to be part of the QTGui module either, even though the Class reference says it is.

If it is part of QtGui then you access it like this
QtGui.QFileDialog.getOpenFileName().
There has to be hundreds of examples on the web that you can copy as well.

Sorry to be such a pain about this, but I did try fully qualifying it first (QGui.QfileDialog) with no success either.

Which version of Windows are you using?

PyQT 4.8 seems to work better with Windows7 than Windows XP

I'm running PyQt 4.8.2 for Python 2.7, however, I also noticed that pyuic4 was called 'pyuic.py' and wouldn't run either. When I renamed it to 'pyuic4.py' it ran. I wonder if there was a half hearted attempt for 2.7 compatibility and the PyQT4 for 2.7 is just plain 'broken'?...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.