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

convert QByteArray to bytes



  • Hello,
    I need convert QByteArray to standart pythons bytes.
    I try convert it but I recieve SIGSEGV.
    //Python 3.7.3 , PySide2 5.13.2

    Can you please help me??

    from PySide2.QtCore import QByteArray
    
    pba=b'\x00\x02'
    qba=QByteArray(b'\x00\x02')
    # convert=bytes(qba)  # SIGSEGV
    
    print("pba typ:"+str(type(pba))+" val:"+str(pba))
    print("qba typ:"+str(type(qba))+" val:"+str(qba))
    
    print("Int pba:"+str(int.from_bytes(pba, byteorder="big", signed=True)))
    print("Int qba:"+str(int.from_bytes(qba, byteorder="big", signed=True)))     #SIGSEGV
    


  • @poucz said in convert QByteArray to bytes:

    convert=bytes(qba) # SIGSEGV
    print("Int qba:"+str(int.from_bytes(qba, byteorder="big", signed=True))) #SIGSEGV

    Both of these work fine for me. Ubuntu 20.04, Python 3.8.5, Qt/PySide2 either 5.12.8 or 5.15.0, not sure which (but I think the latter)!



  • Thank you,
    after update it working!!
    Amazing....

    sudo pip3 install -upgrade  PySide2
    

Log in to reply