QT, ctypes dll and SEG Faults

sapsi saptarshi.guha at gmail.com
Sun Aug 17 05:37:45 CEST 2008


Hello,
Below is a small class using ctypes and libspectre to read a
postscript file.
My program is a PyQT 4.4 application  and when the user clicks on a
entry in a QTableWidget, i run

PostScriptImage( filename_as_contained_in_clicked_tableWidgetItem )
However on i get a segfault while trying document_load.
Surprisingly, before i run sys.exit(app.exec_()) (i.e before the app
starts) if run PostScriptImage(command_line_specified_ps_file) it
works!

I know the ctypes so file works with QT since i wrote an application
using it, but i hadn't separated the ctypes stuff into separate class
(i.e the spectre code was in the widget method).

Any ideas why the crash?

Regards
Saptarshi
--Python Code--
class PostScriptImage:
    def __init__(self,filename):
        print "Doc New"
        self.document=libspec.spectre_document_new()
        print "Load Doc" , filename
        #############crashed in the following
line#########################
        libspec.spectre_document_load(self.document,filename)
        print "Done load doc"
        if libspec.spectre_document_status(self.document):
            return False
        self.scale=[1.0,1.0]
        self.quicksetup()

    def quicksetup(self):
        print "RC"
        rc=libspec.spectre_render_context_new()
        print "Get 0th Page"
        page=libspec.spectre_document_get_page (self.document, 0)
        if libspec.spectre_document_status(self.document):
            raise Exception("Spectre:Setup Document Error")
        w= c_int()
        h= c_int()
        print "Page Size"
        libspec.spectre_page_get_size(page, byref(w),byref(h))
        self.initialSize=(h.value*1.0,w.value*1.0)
        self.initialAspect=float(h.value)/float(w.value)
 
self.npages=libspec.spectre_document_get_n_pages(self.document)



More information about the Python-list mailing list