[Qt-interest] QWidget::find returns zero all the time with valid WId

Görög Veronika gorog.veronika at gmail.com
Wed Dec 10 11:19:33 CET 2008


Dear All,

I have a technical question. I use qt just for a short time.
I use it on linux (Kubuntu 8.10 at this time).

I would like to find a running QWidget by winid.
With the help of "xdotool search" I have found successfully my qt
application (let's call it test1).
I have written an other c++ program (let's call it test2) which use also
xdotool to find the winid of the application by name.
The Winid is correct, because I write it out to the standard output also
from test1 and test2, and they are the same.
I check also the parent of the QWidget, and it is 0.

If I use QWidget::find in test1, it finds the QWidget successfully.
But if I use QWidget::find in test2 with the same winid (test1 is still
running of course), it returns zero...

Here is a part of my code in test1:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    QApplication app(argc, argv);

    MyWidget widget;
    widget.setGeometry(100, 100, 500, 355);
    widget.show();

    QTextStream out(stdout);
    out << "Window id: " << widget.winId() << "\n";
    out << "Parent widget: " << widget.parentWidget() << "\n";

    QWidget * qw = QWidget::find(widget.winId());
    if (qw) {
    out << "Catched in test1" << "\n"; // it is written
    }

    {
    out << "All widgets in this application:\n";
    foreach (QWidget *w, QApplication::allWidgets()) {
        out << "\t" << w->objectName() << ":" << w->winId() << " (parent:"
<< ((w->parentWidget())?((w->parentWidget())->winId()):0) << ")\n";
    }
    }

    out.flush();

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

And test2:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <cstdio>
#include <iostream>
#include <QWidget>
#include <sstream>

using namespace std;

int main(int , char** ) {

    FILE * fstr;
    int buf;
    fstr = popen("xdotool search --onlyvisible --name test1","r");
    fscanf(fstr,"%d",&buf);
    cout << "WId of test1: " << buf << endl;
    pclose(fstr);

    stringstream str;
    str << "xdotool windowactivate " << buf;

    system(str.str().c_str());

    QWidget * qw = QWidget::find(buf);

    if (qw) {
    cout << "Catched" << endl; // never written
    }

    return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Can anyone help me, what did I wrong? Or what I missed?

Thank you a lot in advance,
Veronika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081210/256ec0f2/attachment.html 


More information about the Qt-interest-old mailing list