example needed: sip + Qt

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Uwe Mayer

    #1

    example needed: sip + Qt

    Hi,

    can someone provide me with a running example for subclassing QWidget (or
    something similarly simple) in C++ and then creating SIP (4.x+) bindings
    for in for Python (2.3+)?

    I am looking for something I can start of with and work my way towards more
    complicated stuff (with Qt).

    The QLabel example in the SIP reference manual yields syntax errors for me.
    Same with:


    thanks,
    Uwe
  • Craig Ringer

    #2
    Re: example needed: sip + Qt

    On Fri, 2005-01-28 at 13:30 +0100, Uwe Mayer wrote:[color=blue]
    > Hi,
    >
    > can someone provide me with a running example for subclassing QWidget (or
    > something similarly simple) in C++ and then creating SIP (4.x+) bindings
    > for in for Python (2.3+)?[/color]

    Out of curiosity, would this be for an extension module used in an
    embedded Python interpreter, or for plain extension module for use with
    a standalone interpreter?

    I'm afraid I can't help you with your specific problem, though I'll be
    interested to hear if anybody here does know.

    If you don't have any luck here, try the PyQt/PyKDE list (and search its
    archives first).

    --
    Craig Ringer

    Comment

    • Phil Thompson

      #3
      Re: example needed: sip + Qt

      > Hi,[color=blue]
      >
      > can someone provide me with a running example for subclassing QWidget (or
      > something similarly simple) in C++ and then creating SIP (4.x+) bindings
      > for in for Python (2.3+)?
      >
      > I am looking for something I can start of with and work my way towards
      > more
      > complicated stuff (with Qt).
      >
      > The QLabel example in the SIP reference manual yields syntax errors for
      > me.[/color]

      What syntax errors? If there is a documentation bug then I'll fix it.

      Phil

      Comment

      • Uwe Mayer

        #4
        Re: example needed: sip + Qt

        On Friday 28 January 2005 14:47 pm, Phil Thompson wrote:[color=blue][color=green]
        > > The QLabel example in the SIP reference manual yields syntax errors for
        > > me.[/color]
        >
        > What syntax errors? If there is a documentation bug then I'll fix it.[/color]

        I'll come to that a little later, that happened in the simple c++ word
        example.

        I am currently fiddling around with the QLabel example. I copied the example
        and tried it out. First problem was that the generated makefile does not
        attempt to compile the original hello.cpp sources.

        So I wrote a configure script and a Makefile.am for that.
        It was not clear to me what type of archive or object was needed, so I first
        tried creating a normal object file, then libtool archives and then normal
        archives. It turned out I needed a normal archive an the library search path
        has to be extended to include the current directory (-L.), i.e. where the
        libhello.a lies.
        My only way of doing so was edditing the Makefile generated by configure.py.
        Is there a way of telling that to configure.py?

        So now the hello.cpp example compiles. I fire up python:[color=blue][color=green][color=darkred]
        >>> import hello[/color][/color][/color]
        Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        ImportError: ./hello.so: undefined symbol: _ZTV5Hello

        $ c++filt _ZTV5Hello
        vtable for Hello

        The compilation did not give any warnings or error messages. Any ideas?

        Thanks
        Uwe
        --
        It would seem that evil retreats when forcibly confronted.
        -- Yarnek of Excalbia, "The Savage Curtain", stardate 5906.5

        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.2.5 (GNU/Linux)

        iQEVAwUAQfq6JeU 60gD77wDfAQJoiQ f/UIH66LxzzrxqwUN EIOFruIuMmICoWv qZ
        S/INqzmLaOzhcpoj/lN1i0YjroGT1AWR 08LtIuew4JCQX0I QejgZ0nefzMDjgD s4
        BLcL1Aofj6CQm5t VdEglZvCZ9XXE3V KuXgQJtU7xVuhW2 JEHsMLuGREdgpph xGl0
        I67HRD//+/m7F66a3/CEfurycvljjNenC kn3mCMKBHnXGNXX 2TeE8dtYPVGPcN9 n
        8SmVsAOcR3g/SsgEJSSYxi2pZY4 7gn95AEqAZhB7XS JNBp/xbFEk5Ha1XInvfs Bw
        uuePMDwzhOPsZNa uJxpnoYWKPg+gcG ukqAFi4zoXRA6Zv U9xgO3gXg==
        =FFcq
        -----END PGP SIGNATURE-----

        Comment

        • Uwe Mayer

          #5
          Re: example needed: sip + Qt

          On Friday 28 January 2005 14:24 pm, Craig Ringer wrote:[color=blue]
          > Out of curiosity, would this be for an extension module used in an
          > embedded Python interpreter, or for plain extension module for use with
          > a standalone interpreter?[/color]

          I am writing an application program using Python and PyQt:
          Savannah is a central point for development, distribution and maintenance of free software, both GNU and non-GNU.


          At one point I am using a QListView but need my items to be sorted
          numerically. There is no function to set the sort-criterea and the solution
          to this is subclassing QListViewItem and overwrite the comparison functions.
          However, doing so in Python was awfully slow for a greater number of items,
          so I want to rewrite this in C++ and wrap it back to python.

          Ciao
          Uwe
          --
          Kilroe hic erat!

          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.2.5 (GNU/Linux)

          iQEVAwUAQfq7GOU 60gD77wDfAQJgtA f/QsZbbCuNO3vcrf8 TOMv1Vcti7w/iMw/W
          fBJkcIokbX6HrnU 4oVWnHc8Zz1DAXs xMSNPp2bC65TfPN gGzepEJHX/LvHhvHTOR
          BN38BmmXhZysCPj +hE8a0sXs/4mCOZVBfjJ9Wn5h RsymMSZ0/R+oc2KfPLZSM0Ga
          eri+rokfW+e4JEC M5YVOc9pXM6rWY7 aNC+NEx1m05Z3t+ 28CHwH+Kfw+qQfN DXyI
          va84m6kNe3alCSX gGwRK5q6639BjBj W36xjdfzxl+sCAC cIBB6xeJZ5Hhgc6 1hWK
          6N6ZIBomzM1QgC3 sAUK24cjbh0BMpO JweBKD18tFG2prU KSb3tSyRA==
          =55t6
          -----END PGP SIGNATURE-----

          Comment

          • Uwe Mayer

            #6
            Re: example needed: sip + Qt

            Friday 28 January 2005 23:18 pm Uwe Mayer wrote:[color=blue]
            > Traceback (most recent call last):
            > File "<stdin>", line 1, in ?
            > ImportError: ./hello.so: undefined symbol: _ZTV5Hello
            >
            > $ c++filt _ZTV5Hello
            > vtable for Hello
            >
            > The compilation did not give any warnings or error messages. Any ideas?[/color]

            $ ldd -d hello.so
            libqt-mt.so.3 => /usr/lib/libqt-mt.so.3 (0x40057000)
            libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4190c000)
            libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x4154e000)
            libpthread.so.0 => /lib/tls/libpthread.so.0 (0x41173000)
            libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40743000)
            libm.so.6 => /lib/tls/libm.so.6 (0x4114f000)
            libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x407fd000)
            libc.so.6 => /lib/tls/libc.so.6 (0x41019000)
            libfontconfig.s o.1 => /usr/lib/libfontconfig.s o.1 (0x418d8000)
            libaudio.so.2 => /usr/lib/libaudio.so.2 (0x40807000)
            libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4191c000)
            libpng12.so.0 => /usr/lib/libpng12.so.0 (0x4081c000)
            libz.so.1 => /usr/lib/libz.so.1 (0x41856000)
            libXrender.so.1 => /usr/lib/libXrender.so.1 (0x41749000)
            libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x40842000)
            libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x41734000)
            libXft.so.2 => /usr/lib/libXft.so.2 (0x416e1000)
            libfreetype.so. 6 => /usr/lib/libfreetype.so. 6 (0x42487000)
            libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x42583000)
            libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x4256a000)
            libdl.so.2 => /lib/tls/libdl.so.2 (0x41184000)
            /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
            libexpat.so.1 => /usr/lib/libexpat.so.1 (0x40847000)
            undefined symbol: _ZTV5Hello (./hello.so)
            undefined symbol: _ZNK5Hello9clas sNameEv (./hello.so)
            undefined symbol: _ZN5Hello7qt_ca stEPKc (./hello.so)
            undefined symbol: _ZN5Hello9qt_in vokeEiP8QUObjec t (./hello.so)
            undefined symbol: _ZN5Hello7qt_em itEiP8QUObject (./hello.so)
            undefined symbol: _ZN5Hello11qt_p ropertyEiiP8QVa riant (./hello.so)
            undefined symbol: _ZTI5Hello (./hello.so)
            undefined symbol: _Py_NoneStruct (./hello.so)
            undefined symbol: PyCObject_Type (./hello.so)

            Uwe

            Comment

            • Uwe Mayer

              #7
              Re: example needed: sip + Qt

              Friday 28 January 2005 23:39 pm Uwe Mayer wrote:
              [color=blue]
              > Friday 28 January 2005 23:18 pm Uwe Mayer wrote:[color=green]
              >> Traceback (most recent call last):
              >> File "<stdin>", line 1, in ?
              >> ImportError: ./hello.so: undefined symbol: _ZTV5Hello
              >>
              >> $ c++filt _ZTV5Hello
              >> vtable for Hello
              >>
              >> The compilation did not give any warnings or error messages. Any ideas?[/color]
              >
              > $ ldd -d hello.so
              > libqt-mt.so.3 => /usr/lib/libqt-mt.so.3 (0x40057000)
              > libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4190c000)
              > libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x4154e000)
              > libpthread.so.0 => /lib/tls/libpthread.so.0 (0x41173000)
              > libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40743000)
              > libm.so.6 => /lib/tls/libm.so.6 (0x4114f000)
              > libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x407fd000)
              > libc.so.6 => /lib/tls/libc.so.6 (0x41019000)
              > libfontconfig.s o.1 => /usr/lib/libfontconfig.s o.1 (0x418d8000)
              > libaudio.so.2 => /usr/lib/libaudio.so.2 (0x40807000)
              > libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4191c000)
              > libpng12.so.0 => /usr/lib/libpng12.so.0 (0x4081c000)
              > libz.so.1 => /usr/lib/libz.so.1 (0x41856000)
              > libXrender.so.1 => /usr/lib/libXrender.so.1 (0x41749000)
              > libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x40842000)
              > libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x41734000)
              > libXft.so.2 => /usr/lib/libXft.so.2 (0x416e1000)
              > libfreetype.so. 6 => /usr/lib/libfreetype.so. 6 (0x42487000)
              > libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x42583000)
              > libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x4256a000)
              > libdl.so.2 => /lib/tls/libdl.so.2 (0x41184000)
              > /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
              > libexpat.so.1 => /usr/lib/libexpat.so.1 (0x40847000)
              > undefined symbol: _ZTV5Hello (./hello.so)
              > undefined symbol: _ZNK5Hello9clas sNameEv (./hello.so)
              > undefined symbol: _ZN5Hello7qt_ca stEPKc (./hello.so)
              > undefined symbol: _ZN5Hello9qt_in vokeEiP8QUObjec t (./hello.so)
              > undefined symbol: _ZN5Hello7qt_em itEiP8QUObject (./hello.so)
              > undefined symbol: _ZN5Hello11qt_p ropertyEiiP8QVa riant (./hello.so)
              > undefined symbol: _ZTI5Hello (./hello.so)[/color]
              [color=blue]
              > undefined symbol: _Py_NoneStruct (./hello.so)
              > undefined symbol: PyCObject_Type (./hello.so)[/color]

              Those last two can be removed if you link against libpython2.3.so and by
              appending -lpython2.3 to the libs in the Makefile.

              Uwe

              Comment

              • Phil Thompson

                #8
                Re: example needed: sip + Qt

                So have you created the library you are trying to wrap? The documentation is
                describing how to wrap a library and describes a fictional library as the
                basis for the example.

                Phil

                On Friday 28 January 2005 11:02 pm, Uwe Mayer wrote:[color=blue]
                > Friday 28 January 2005 23:39 pm Uwe Mayer wrote:[color=green]
                > > Friday 28 January 2005 23:18 pm Uwe Mayer wrote:[color=darkred]
                > >> Traceback (most recent call last):
                > >> File "<stdin>", line 1, in ?
                > >> ImportError: ./hello.so: undefined symbol: _ZTV5Hello
                > >>
                > >> $ c++filt _ZTV5Hello
                > >> vtable for Hello
                > >>
                > >> The compilation did not give any warnings or error messages. Any ideas?[/color]
                > >
                > > $ ldd -d hello.so
                > > libqt-mt.so.3 => /usr/lib/libqt-mt.so.3 (0x40057000)
                > > libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4190c000)
                > > libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x4154e000)
                > > libpthread.so.0 => /lib/tls/libpthread.so.0 (0x41173000)
                > > libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40743000)
                > > libm.so.6 => /lib/tls/libm.so.6 (0x4114f000)
                > > libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x407fd000)
                > > libc.so.6 => /lib/tls/libc.so.6 (0x41019000)
                > > libfontconfig.s o.1 => /usr/lib/libfontconfig.s o.1 (0x418d8000)
                > > libaudio.so.2 => /usr/lib/libaudio.so.2 (0x40807000)
                > > libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4191c000)
                > > libpng12.so.0 => /usr/lib/libpng12.so.0 (0x4081c000)
                > > libz.so.1 => /usr/lib/libz.so.1 (0x41856000)
                > > libXrender.so.1 => /usr/lib/libXrender.so.1 (0x41749000)
                > > libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x40842000)
                > > libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x41734000)
                > > libXft.so.2 => /usr/lib/libXft.so.2 (0x416e1000)
                > > libfreetype.so. 6 => /usr/lib/libfreetype.so. 6 (0x42487000)
                > > libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x42583000)
                > > libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x4256a000)
                > > libdl.so.2 => /lib/tls/libdl.so.2 (0x41184000)
                > > /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)
                > > libexpat.so.1 => /usr/lib/libexpat.so.1 (0x40847000)
                > > undefined symbol: _ZTV5Hello (./hello.so)
                > > undefined symbol: _ZNK5Hello9clas sNameEv (./hello.so)
                > > undefined symbol: _ZN5Hello7qt_ca stEPKc (./hello.so)
                > > undefined symbol: _ZN5Hello9qt_in vokeEiP8QUObjec t (./hello.so)
                > > undefined symbol: _ZN5Hello7qt_em itEiP8QUObject (./hello.so)
                > > undefined symbol: _ZN5Hello11qt_p ropertyEiiP8QVa riant (./hello.so)
                > > undefined symbol: _ZTI5Hello (./hello.so)
                > >
                > > undefined symbol: _Py_NoneStruct (./hello.so)
                > > undefined symbol: PyCObject_Type (./hello.so)[/color]
                >
                > Those last two can be removed if you link against libpython2.3.so and by
                > appending -lpython2.3 to the libs in the Makefile.
                >
                > Uwe[/color]

                Comment

                • Uwe Mayer

                  #9
                  Re: example needed: sip + Qt

                  Saturday 29 January 2005 00:23 am Phil Thompson wrote:
                  [color=blue]
                  > So have you created the library you are trying to wrap? The documentation
                  > is describing how to wrap a library and describes a fictional library as
                  > the basis for the example.[/color]

                  No, the extracts from before are from the code example of the fictional
                  library with no further implementation.

                  By now I also found the problem: the poor python programmer did not care to
                  create the makefile (for building hello.cpp and hello.h) with qmake and
                  thus there were no moc files and that stupid programmer (me) could not link
                  against them.

                  It compiles and loads in python now.
                  Thanks
                  Uwe

                  Comment

                  Working...