PDA

View Full Version : Loosing keyboard focus when embbeding xterm using QX11EmbedContainer



smarcus
24th November 2011, 10:08
I am embeding a xterm using QX11EmbedContainer. If I click on a different window outside the application and return back to the embeded xterm I loose the keyboard focus. Below is a small test case of what am I doing. What am I missing.

Thanks,

Shaul



//---------------------- main.cpp ---------------------------------

#include <qapplication.h>

#include "my_main.h"

int main(int argc, char **argv)
{
QApplication a(argc, argv);

my_main* top = new my_main;
top->show();
return a.exec();
}

//-----------my_main.h-------------------------------------------------------


#include <QApplication>
#include <QMainWindow>
#include <QAction>
#include <QMenuBar>
#include <QMenu>
#include <QFrame>
#include <QX11EmbedContainer>
#include <QProcess>
#include <QHBoxLayout>

class my_main : public QMainWindow
{
Q_OBJECT
public:
my_main() : QMainWindow()
{
setObjectName("a_out");
QMenu* fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction(action);
action = new QAction("&Quit", this);
action->setShortcut(QKeySequence("Ctrl+Q"));
connect(action, SIGNAL(activated()), qApp, SLOT(quit()));
fileMenu->addAction(action);
QHBoxLayout * layout = new QHBoxLayout();
m_frame = new QX11EmbedContainer; //(this);
m_frame->setFocusPolicy( Qt::StrongFocus );
m_frame->show();
layout->addWidget(m_frame);
setLayout(layout);
setCentralWidget(m_frame);
run();
}

~my_main() {}

public slots:

void run()
{
QProcess* proc = new QProcess;
QString cmd = "/usr/X11/bin/xterm";
QStringList args;
args << "-into" << QString::number(m_frame->winId());
connect(proc, SIGNAL(processExited()),
this, SLOT(processExited()));
proc->start(cmd, args );
}

void processExited()
{
QProcess* proc = dynamic_cast<QProcess*>(sender());
if (proc == NULL)
{
return;
}
proc->deleteLater();
}

signals:

private:
QProcess* m_proc;
QX11EmbedContainer* m_frame;
};