I have built Python2.6.8 in Visual Studio 2008, and also built PythonQt in same (64 bit, release).
Python works fine, and no build problems.
I also built the PyGuiExample to try things out.
When I run the PyGuiExample, it runs fine, but the python script example.py does not run correctly.
The python console window appears, but give and error :
NameError: name 'QGroupBox' is not defined.
The top line of the _example.py _script is
fromPythonQt.QtGuiimport*
It seems that this import is failing. The python console window that appears works - I can type in basic commands and get the correct result back.
Any ideas or suggestions as to what might be wrong are appreciated.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just guessing here - but which version of Qt did you build it with?
PythonQt's Qt bindings (PythonQt.*) are built using a generator script (see the "generator" folder) against a particular version of Qt. If they were built with a different version of Qt to what you're building with, that might cause some errors like the ones you're seeing. I can't remember off-hand what version the bindings that come with the download were built with, though - probably 4.6 or 4.7…?
Cheers,
- Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I built using Qt 4.8 with VisualStudio 2008 and the Qt plugin.
I see the generator folder (under PythonQt2.1_Qt4.8) so I'm assuming that the bindings were already generated for 4.8, but the README says that the bindings are for 4.6.2.
Is the idea that I create a VisualStudio solution from the generator.pro file and then run that as some console app? What does this do and what are the next steps?
Thanks for your help.
Jeff.
I did build PythonQt using this build as well.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's for Linux, but hopefully should be clear enough. LD_LIBRARY_PATH is just a DLL load path, and 'make' is the build step.
In essence, though, yes: generator.pro will give you the generator executable, and running that will give you a set of CPP files for bindings that should be automatically built with the PythonQt_QtAll project to give you access to the Qt libraries in your Python app. I think you can also tweak the XML files in the generator directory to alter what code gets generated, but I haven't messed around with it much myself.
Hope that helps.
- Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't think that the generator is the problem. The DLLs load just fine, and I read in another thread that the existing bindings (4.6.1) will work with Qt 4.8, you just don't get any new bindings. So things like QGroupBox and QString should work.
I built the example PyGuiEample app cutting out PythongQt_QtAll since that wants to bring in everything (WebKit, SQL, XML, etc.) and I only need QtGui and QtCore - which I think should be accessible after calling PythonQt::init().
Do you know if PythonQt can be used without including all the bindings (i.e. leaving out PythonQt_QtAll)? I'm at a loss as to why the bindings are not working for this simple example app.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've answered part of my question: PythonQt only has a very rudimentary set of Qt classes inclued from QtGui and QtCore. This is what I show when doing a dir(QtCore) and dir(QtGui) in Python:
Looking into PythonQt_QtAll, I see that the classes I'm looking for (QString, QGroupBox) are there, but I don't want to have to include all the Qt dlls for things not used in my app (like Webkit, QtXML, QtSql, etc.)
So, is there a nice, simple way to cut down what's in QtAll? I could make another project and just exclude things from the project, but I thought there might be a "built-in" way to customize what you wanted bound.
Any help is appreciated. And thanks to Chris for following me through this so far.
Jeff.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Currently there is not "built-in" way to do this with PythonQt/qmake, but as you said, you can quite easily build an extra DLL which only contains the classes that you need. I am not sure, maybe the cmake build files (courtesy of the Slicer community) allow that kind of configuration.
In MeVisLab we actually go a bit further and created loadable C-Python modules for each of the Qt DLLs, so that e.g. import PythonQt.QtGui will load the QtGui binding. Unfortunately I did not have time to contribute this to the PythonQt project itself.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I made a few changes to the bindings in PythonQt_QtAll some time back when building for Qt 4.5, but have to admit I mostly went brute force and hacked out a bunch of includes and things from the generated CPP files and such. I found that reasonably easy to do, so I'm sure you (Jeff) will be able to do the same if it's the best solution. Sorry I'm not much more help - but as I say, I haven't built it in ages now; I was just trying to think of something that might be useful :)
- Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is now resolved. I modified the PythonQt_QtAll project (in VisualStudio 2008) to remove references to unwanted libraries. My version with PyGuiExample now works, without the needs to have dlls for QtWebkit, QtXML, QtSql present.
Thanks to Florian and Chris for help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have built Python2.6.8 in Visual Studio 2008, and also built PythonQt in same (64 bit, release).
Python works fine, and no build problems.
I also built the PyGuiExample to try things out.
When I run the PyGuiExample, it runs fine, but the python script example.py does not run correctly.
The python console window appears, but give and error :
The top line of the _example.py _script is
It seems that this import is failing. The python console window that appears works - I can type in basic commands and get the correct result back.
Any ideas or suggestions as to what might be wrong are appreciated.
Thanks.
Hi Jeff,
Just guessing here - but which version of Qt did you build it with?
PythonQt's Qt bindings (PythonQt.*) are built using a generator script (see the "generator" folder) against a particular version of Qt. If they were built with a different version of Qt to what you're building with, that might cause some errors like the ones you're seeing. I can't remember off-hand what version the bindings that come with the download were built with, though - probably 4.6 or 4.7…?
Cheers,
- Chris
Chris,
Thanks for your reply.
I built using Qt 4.8 with VisualStudio 2008 and the Qt plugin.
I see the generator folder (under PythonQt2.1_Qt4.8) so I'm assuming that the bindings were already generated for 4.8, but the README says that the bindings are for 4.6.2.
Is the idea that I create a VisualStudio solution from the generator.pro file and then run that as some console app? What does this do and what are the next steps?
Thanks for your help.
Jeff.
I did build PythonQt using this build as well.
Hi Jeff,
I haven't built it myself for about a year, but here's the relevant part of my build script:
It's for Linux, but hopefully should be clear enough. LD_LIBRARY_PATH is just a DLL load path, and 'make' is the build step.
In essence, though, yes: generator.pro will give you the generator executable, and running that will give you a set of CPP files for bindings that should be automatically built with the PythonQt_QtAll project to give you access to the Qt libraries in your Python app. I think you can also tweak the XML files in the generator directory to alter what code gets generated, but I haven't messed around with it much myself.
Hope that helps.
- Chris
Chris,
I don't think that the generator is the problem. The DLLs load just fine, and I read in another thread that the existing bindings (4.6.1) will work with Qt 4.8, you just don't get any new bindings. So things like QGroupBox and QString should work.
I built the example PyGuiEample app cutting out PythongQt_QtAll since that wants to bring in everything (WebKit, SQL, XML, etc.) and I only need QtGui and QtCore - which I think should be accessible after calling PythonQt::init().
Do you know if PythonQt can be used without including all the bindings (i.e. leaving out PythonQt_QtAll)? I'm at a loss as to why the bindings are not working for this simple example app.
I've answered part of my question: PythonQt only has a very rudimentary set of Qt classes inclued from QtGui and QtCore. This is what I show when doing a dir(QtCore) and dir(QtGui) in Python:
Looking into PythonQt_QtAll, I see that the classes I'm looking for (QString, QGroupBox) are there, but I don't want to have to include all the Qt dlls for things not used in my app (like Webkit, QtXML, QtSql, etc.)
So, is there a nice, simple way to cut down what's in QtAll? I could make another project and just exclude things from the project, but I thought there might be a "built-in" way to customize what you wanted bound.
Any help is appreciated. And thanks to Chris for following me through this so far.
Jeff.
Currently there is not "built-in" way to do this with PythonQt/qmake, but as you said, you can quite easily build an extra DLL which only contains the classes that you need. I am not sure, maybe the cmake build files (courtesy of the Slicer community) allow that kind of configuration.
In MeVisLab we actually go a bit further and created loadable C-Python modules for each of the Qt DLLs, so that e.g. import PythonQt.QtGui will load the QtGui binding. Unfortunately I did not have time to contribute this to the PythonQt project itself.
I made a few changes to the bindings in PythonQt_QtAll some time back when building for Qt 4.5, but have to admit I mostly went brute force and hacked out a bunch of includes and things from the generated CPP files and such. I found that reasonably easy to do, so I'm sure you (Jeff) will be able to do the same if it's the best solution. Sorry I'm not much more help - but as I say, I haven't built it in ages now; I was just trying to think of something that might be useful :)
- Chris
This is now resolved. I modified the PythonQt_QtAll project (in VisualStudio 2008) to remove references to unwanted libraries. My version with PyGuiExample now works, without the needs to have dlls for QtWebkit, QtXML, QtSql present.
Thanks to Florian and Chris for help.