2017-02-17 12 views
0

どのようにバイトオブジェクトをデータベースに挿入しますか?私はこれを試みるたびに、空の文字列(NULLではない)が挿入されてしまいます。pyqt5がバイトを挿入できません

with open(filepath, 'rb') as f: 
    filehash = hashlib.md5(f.read()).hexdigest() 
img_pkl = pickle.dumps(img, protocol=4) 

record = self.tablemodel.record() 
record.setValue('originfile_path', filepath) 
record.setValue('originfile_hash', filehash) 
record.setValue('image', img_pkl) 
record.setValue('area', area) 
self.tablemodel.insertRecord(-1, record) 

問題はメーリングリストに記載されていますが、決して言及されませんでした。 https://www.riverbankcomputing.com/pipermail/pyqt/2016-April/037260.html また、あなたが代わりに準備された文の缶(彼はまた、exec_対のexec()に関するPyQtはバグを指摘したときに、それはテーブルモデルを使用する方が理にかなっていることが判明した()。あなたが明示的に変換する必要があります

答えて

0

。QByteArray

record.setValue('image', QtCore.QByteArray(img_pkl)) 

注:あなたもfloatを使用してnumpy.float64オブジェクトを変換する必要があります()

関連する問題