Search code examples
pyqt5migrationpyqt4python-2to3

Issue faced while migrating from PyQt4 to PyQt5


I have an GUI application, which is quite big.I have it in Python 2.7. Since Python 2 is no longer being updated, I converted my application to Python 3.8 using 2to3 module. I am facing this problem and have no idea how to solve it. I referred some of the similar problems but did not get anywhere. I have the following error:

QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data) TypeError: qRegisterResourceData(int, bytes, bytes, bytes): argument 2 has unexpected type 'str'

What should I do to get pass this issue?


Solution

  • Resource files on PyQt are actually python scripts with base64 encoded data.

    When porting to newer systems (both python 3 and Qt5) requires proper updating of those files.

    Generally, it can be done by calling again the pyrcc command (pyrcc5 or pyrcc5.exe if both Qt versions are installed), but they can be manually ported, considering the following aspects:

    • the import statement has obviously be modified to PyQt5;
    • all variables (qt_resource_data and qt_resource_name) are bytes literals and require the b'...' prefix;
    
    from PyQt5 import QtCore
    
    qt_resource_data = b"\
        -- raw data --
    "
    
    qt_resource_name = b"\
        -- raw data --
    "