Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2008-05

Getting x11 info from a device context

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luiz Americo Pereira Camara

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 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

zeljko
to Luiz Americo Pereira Camara
Luiz Americo Pereira Camara wrote
X11Info := QWidget_x11Info(Parent); <---------

here is problem, you passed nil widget (parent).

you have to check it first
if parent = Nil then
 Parent := QApplication_desktop()
and then call
  X11Info := QWidget_x11Info(Parent);

I've just tested it and it works for me ;)

zeljko

Luiz Americo Pereira Camara
to zeljko
zeljko wrote 13 lines
On Sunday 04 May 2008 16:04, Luiz Americo Pereira Camara wrote: > X11Info := QWidget_x11Info(Parent); <--------- > here is problem, you passed nil widget (parent). you have to check it first if parent = Nil then Parent := QApplication_desktop() and then call X11Info := QWidget_x11Info(Parent);

Thanks.

I handled the case when Parent is nil by using the QtImage data directly instead of using a xlib drawable.

Luiz