[Qt] Getting x11 info from a device context

Luiz Americo Pereira Camara luizmed at oi.com.br
Sun May 4 16:04:14 CEST 2008


Hi,

I managed to integrate cairo library with win32/gtk/gtk2 widgetsets but 
i'm having problems with Qt under X.

To create a cairo surface under a X server i need a display (PDisplay), 
a drawable (TDrawable) and a visual (PVisual). I tried the following:

The DC is created with CreateCompatibleDC and a Bitmap created with 
CreateBitmap is selected onto that DC.

function CreateSurfaceFromDC(DC: HDC): Pcairo_surface_t;
var
  DeviceContext: TQtDeviceContext absolute DC;
  X11Info: QX11InfoH;
begin
  if QtWidgetSet.IsValidDC(DC) then
  with DeviceContext do
  begin
    X11Info := QWidget_x11Info(Parent);
    Result := cairo_xlib_surface_create(
      QX11Info_display,
      QWidget_winId(Parent),
      QX11Info_visual(X11Info),
      QWidget_width(Parent), QWidget_height(Parent)
      );
    QX11Info_destroy(X11Info);
  end;
end;

But a SIGSEGV occurs at QWidget_x11Info.

Under Qt3 is possible to do the following (from cairo demos):

QCairoWidget::QCairoWidget( QWidget *parent, const char *name )
    : QWidget( parent, name )
{
[..]
    m_surf = cairo_xlib_surface_create ((Display *) x11AppDisplay(), (Drawable) handle(), (Visual *) x11Visual(), width(), height() );
[..]
}


Does another way of doing this? Or is there a bug at QWidget_x11Info?

The full code can be found at: 
https://luipack.bountysource.com/svn/!dirinfo/325/trunk/cairo

Luiz




More information about the Qt mailing list