Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

pyside2-rcc resource compiler not working on desktop



  • Hello All,
    I have a qrc file
    through rcc.exe i got output of .py file
    and then i imported the file but it gives a syntax error
    i am providing the the rcc code as well
    and you can disable the comment and comment the complete path for checking purpose

    import sys
    
    from PySide2 import QtCore, QtWidgets, QtGui
    
    # import succinct_save_rcc
    
    
    class MyWidget(QtWidgets.QWidget):
    
        def __init__(self):
    
            QtWidgets.QWidget.__init__(self)
    
    
            self.button = QtWidgets.QPushButton("Click me!")
    
            self.text = QtWidgets.QLabel()
    
            self.pixmap = QtGui.QPixmap("D:\\All_Projs\\Maya_Projs\\succinct_save\\unwanted_files\\succinct_save.jpg")
    
            # self.pixmap = QtGui.QPixmap(":/succinct_save_prefix/succinct_save.jpg")
    
            self.text.setPixmap(self.pixmap)
    
            self.text.setAlignment(QtCore.Qt.AlignCenter)
    
    
            self.layout = QtWidgets.QVBoxLayout()
    
            self.layout.addWidget(self.text)
    
            self.layout.addWidget(self.button)
    
            self.setLayout(self.layout)
    
    
    
    if __name__ == "__main__":
    
        app = QtWidgets.QApplication(sys.argv)
    
    
        widget = MyWidget()
    
        widget.show()
    
    
        sys.exit(app.exec_())
    

    above is the working version of the code
    but with the full image path
    below is the qrc please run in pyside2 rcc.exe

    <RCC>
      <qresource prefix="succinct_save_prefix">
        <file>succinct_save.jpg</file>
      </qresource>
    </RCC>
    
    

    thank you.


  • Lifetime Qt Champion

    Hi,

    Which version of PySide2 are you using ?
    How did you install it ?



  • @blossomsg What do you mean by syntax error? On the other hand, when converting the resource.qrc file, it must have the name resource_rc.py



  • @SGaist
    Hi,
    PySide2 -- 5.15.0
    installed it through pycharm

    @eyllanesc
    is it mandatory to keep "resource_rc.py"?

    /****************************************************************************
    ** Resource object code
    **
    ** Created by: The Resource Compiler for Qt version 5.15.0
    **
    ** WARNING! All changes made in this file will be lost!
    *****************************************************************************/
    
    static const unsigned char qt_resource_data[] = {
      // D:/All_Projs/Maya_Projs/succinct_save/unwanted_files/succinct_save.jpg
      0x0,0x0,0x6a,0x89,
      0xff,
    
      0xec,0x55,0xd8,0xab,0xb1,0x57,0xff,0xd9,
      
    };
    
    static const unsigned char qt_resource_name[] = {
      // succinct_save_prefix
      0x0,0x14,
      0x4,0xc3,0x94,0x68,
      0x0,0x73,
      0x0,0x75,0x0,0x63,0x0,0x63,0x0,0x69,0x0,0x6e,0x0,0x63,0x0,0x74,0x0,0x5f,0x0,0x73,0x0,0x61,0x0,0x76,0x0,0x65,0x0,0x5f,0x0,0x70,0x0,0x72,0x0,0x65,
      0x0,0x66,0x0,0x69,0x0,0x78,
        // succinct_save.jpg
      0x0,0x11,
      0x9,0x48,0x7a,0xc7,
      0x0,0x73,
      0x0,0x75,0x0,0x63,0x0,0x63,0x0,0x69,0x0,0x6e,0x0,0x63,0x0,0x74,0x0,0x5f,0x0,0x73,0x0,0x61,0x0,0x76,0x0,0x65,0x0,0x2e,0x0,0x6a,0x0,0x70,0x0,0x67,
      
      
    };
    
    static const unsigned char qt_resource_struct[] = {
      // :
      0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,
    0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
      // :/succinct_save_prefix
      0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x2,
    0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
      // :/succinct_save_prefix/succinct_save.jpg
      0x0,0x0,0x0,0x2e,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,
    0x0,0x0,0x1,0x74,0x29,0xf5,0xb3,0x51,
    
    };
    
    #ifdef QT_NAMESPACE
    #  define QT_RCC_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
    #  define QT_RCC_MANGLE_NAMESPACE0(x) x
    #  define QT_RCC_MANGLE_NAMESPACE1(a, b) a##_##b
    #  define QT_RCC_MANGLE_NAMESPACE2(a, b) QT_RCC_MANGLE_NAMESPACE1(a,b)
    #  define QT_RCC_MANGLE_NAMESPACE(name) QT_RCC_MANGLE_NAMESPACE2( \
            QT_RCC_MANGLE_NAMESPACE0(name), QT_RCC_MANGLE_NAMESPACE0(QT_NAMESPACE))
    #else
    #   define QT_RCC_PREPEND_NAMESPACE(name) name
    #   define QT_RCC_MANGLE_NAMESPACE(name) name
    #endif
    
    #ifdef QT_NAMESPACE
    namespace QT_NAMESPACE {
    #endif
    
    bool qRegisterResourceData(int, const unsigned char *, const unsigned char *, const unsigned char *);
    bool qUnregisterResourceData(int, const unsigned char *, const unsigned char *, const unsigned char *);
    
    #ifdef QT_NAMESPACE
    }
    #endif
    
    int QT_RCC_MANGLE_NAMESPACE(qInitResources)();
    int QT_RCC_MANGLE_NAMESPACE(qInitResources)()
    {
        int version = 3;
        QT_RCC_PREPEND_NAMESPACE(qRegisterResourceData)
            (version, qt_resource_struct, qt_resource_name, qt_resource_data);
        return 1;
    }
    
    int QT_RCC_MANGLE_NAMESPACE(qCleanupResources)();
    int QT_RCC_MANGLE_NAMESPACE(qCleanupResources)()
    {
        int version = 3;
        QT_RCC_PREPEND_NAMESPACE(qUnregisterResourceData)
           (version, qt_resource_struct, qt_resource_name, qt_resource_data);
        return 1;
    }
    
    namespace {
       struct initializer {
           initializer() { QT_RCC_MANGLE_NAMESPACE(qInitResources)(); }
           ~initializer() { QT_RCC_MANGLE_NAMESPACE(qCleanupResources)(); }
       } dummy;
    }
    


  • @blossomsg that's C++ code, you must use the "-g" option.

    rcc.exe -g python your_resource.qrc -o your_resource_rc.py 
    

    or

    rcc.exe -g python2 your_resource.qrc -o your_resource_rc.py 
    

    See the help:

    rcc.exe  --help
    

    In pyqt5 the extension is used, perhaps in pyside2 it is not necessary.



  • @eyllanesc
    I knew it was c++ but did not know we could enable python with -g
    completely forgot to check the help.
    and yes with pyqt5 it was generating proper python but not with pyside2.

    Man you are a genius thanks a bunch!


  • Lifetime Qt Champion

    @blossomsg out of curiosity, why not use pyside2-rcc.exe like your thread title suggests you did ?



  • @SGaist
    Hey,
    Sorry for late reply
    but they don't package pyside2-rcc.exe anymore, i got to know this through maya
    https://forums.autodesk.com/t5/maya-programming/maya-2018-pyside-rcc-missing/td-p/9497915
    they have not updated the docs
    even they use rcc.exe
    due which then i started using PyQt4 rcc

    and through pycharm i have downloaded the latest pyside2 5.15.0
    but again rcc.exe

    i can be wrong but if so i should be able to find the pyside2-rcc.exe in the site-package folder


Log in to reply