tags:

views:

53

answers:

1

I want use qt to control some other windows, so I write this code:

#define protected public //just for test
...
WId id = 0x00000001 //some real wid
QWidget w;
w.create(id, false, false);
w.hide();

after I run this code, the window crashes, and I got:

:X Error: BadAccess (attempt to access private resource denied) 10

I'm using ubuntu10.04 with qt4, anyone has sample in QWidget::create?

A: 

this is my approach, still has bug though.

#include <sys/select.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <regex.h>

#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>


#define SIZE_USEHINTS (1L << 0)

Display *display = 0;

void initDisplay()
{
    if (display == 0)
        display = XOpenDisplay(getenv("DISPLAY"));
}

int _is_success(const char *funcname, int code) {
  if (code != 0)
    fprintf(stderr, "%s failed (code=%d)\n", funcname, code);
  return code;
}

int window_change(Window wid, int x, int y, int w, int h) {
    initDisplay();
    XWindowChanges wc;
    wc.x = x;
    wc.y = y;
    wc.width = w;
    wc.height = h;
    int ret = XConfigureWindow(display, wid, CWX | CWY | CWWidth | CWHeight, &wc);
    XFlush(display);
    return _is_success("XConfigureWindow", ret == 0);
}
linjunhalida