QWidget在x11中创建问题

时间:2010-08-06 10:43:56

标签: qt x11

我想用qt来控制其他一些窗口,所以我写这段代码:

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

运行此代码后,窗口崩溃了,我得到了:

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

我正在使用带有qt4的ubuntu10.04,有人在QWidget :: create中有样本吗?

1 个答案:

答案 0 :(得分:0)

这是我的方法,但仍有bug。

#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);
}
相关问题