开发者

Qt 4.7+Xlib crash on QWidget::winId() method

Sorry for my english, but I have the next problem. I am writing a window manager using Qt 4.7 and Xlib. I have class Manager that inherits QApplication and reimplemented method X11EventFilter in it. In X11EventFilter method I catch necessary events from XServer. When I receive MapRequest event, I catch appearing of new window and reparent it to my own widget. And when I create that widget and call QWidget::show() or QWidget::winId() methods, program crashes. What is the problem?

Here is a method where widget is creating. I wonder, when this function calls few times on start of program, everything is OK.

void Manager::createClientWindow(Qt::HANDLE pWinID)
{
    QMWindowWidget *lWindowWidget = new QMWindowWidget(pWinID);
    /*some code*/
    lWindowWidget->show();//crash is here
    Qt::HANDLE widgetId = lWindowWidget->winId();//and here
    /*some code*/
}

Here is a x11EventFilter method where createClientWindow function is called

bool Manager::x11EventFilter(XEvent *pEvent)
{
    switch(pEvent.type)
    {
    /*some code*/
    case MapRequest:
    {
        Qt::HANDLE lWindow = pEvent->xmaprequest.window;

        QMWindowWidget* lWidget = findWidget(lWindow);
开发者_开发知识库        if (!lWidget)
        {
            lWidget = dynamic_cast<QMWindowWidget*>(QWidget::find(lWindow));
        }

        if (lWidget)
        {
            XMapWindow(QX11Info::display(), lWindow);
            lWidget->show();
            XRaiseWindow(QX11Info::display(), lWidget->winId());
            return true;
        }
        else
        {
            createClientWindow(lWindow);//here is where function is called
            return true;
        }
    }
    break;
    /*some code*/
    }    //switch
    return false;
}


The problem most likely resides in the code represented by /*some code*/. Since it is not known what's there, it's very difficult to pinpoint the exact cause of the problem. If you cannot show all the code, you will have to track the problem down yourself.

You will need to build in debug mode and link with the debug version of Qt. Then when the crash happens, look at the exact line of Qt source and analyse the broken data structures with a debugger and try to figure out why they are broken. Maybe set a watchpoint on a problematic variable and find out what code writes an invalid value there.

In order to program in low level languages such as C and C++ one has to learn how to do this stuff.


Problem is resolved! I paste this two strings before QApplication::exec()

XClearWindow(QX11Info::display(), QX11Info::appRootWindow());
XSync(QX11Info::display(), false);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜