J_ocaetano
3rd December 2010, 18:00
Hi, in my applicatin I have two widgets constructed separately. Using QX11EmbedContainer + QProcess I can execute the second widget inside the first, and it works fine.
The problem is when I stop the second when it has the focus and I change the actual tab(First widget has a QtabWidget), the keyboard simply stop working.
I have no idea what might be happening.
This is my code:
First Widget:
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::Prototype_tab)
{
showMaximized();
ui->setupUi(this);
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(startPrototype()));
connect(ui->stopButton, SIGNAL(pressed()), this, SLOT(stopPrototype()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::startPrototype() {
ui->startButton->setEnabled(false);
ui->label_screenshot->hide();
container = new QX11EmbedContainer(ui->tabWidget);
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
container->setMinimumSize(600, 600);
ui->gridLayout->addWidget(container,1,1);
myProcess = new QProcess(container);
myProcess->setWorkingDirectory("../../simpleX11Embed/build");
myProcess->start("./simpleX11Embed", QStringList() << "-into" << QString().setNum(container->winId()));
ui->stopButton->setEnabled(true);
connect(myProcess, SIGNAL(finished(int)), this, SLOT(enableStartButton()));
}
void MainWindow::stopPrototype() {
myProcess->close();
}
void MainWindow::enableStartButton() {
container->close();
ui->label_screenshot->show();
ui->stopButton->setEnabled(false);
ui->startButton->setEnabled(true);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Second Widget :
#include "simpleX11Embed.h"
MainWindow::MainWindow(QWidget *parent) : QX11EmbedWidget(parent) {
QTextEdit *textBrowser = new QTextEdit();
textBrowser->setFocusPolicy(Qt::StrongFocus);
textBrowser->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *widlayout = new QVBoxLayout(this);
widlayout->addWidget(textBrowser);
}
int main(int argc, char *argv[]){
QApplication app(argc, argv);
if(app.arguments().count() > 2)
if (app.arguments()[1] == "-into") {
QString windowId(app.arguments()[2]);
MainWindow window;
window.embedInto(windowId.toULong());
window.show();
return app.exec();
}
MainWindow w;
w.show();
return app.exec();
}
I'm attaching the source too.
To get on my error when executing the SimpleX11Container:
press start button, press tab, press tab again, type anything int the text edit, press stop button and press the right arrow to change tab, then the keyboard stop.
The problem is when I stop the second when it has the focus and I change the actual tab(First widget has a QtabWidget), the keyboard simply stop working.
I have no idea what might be happening.
This is my code:
First Widget:
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::Prototype_tab)
{
showMaximized();
ui->setupUi(this);
connect(ui->startButton, SIGNAL(pressed()), this, SLOT(startPrototype()));
connect(ui->stopButton, SIGNAL(pressed()), this, SLOT(stopPrototype()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::startPrototype() {
ui->startButton->setEnabled(false);
ui->label_screenshot->hide();
container = new QX11EmbedContainer(ui->tabWidget);
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
container->setMinimumSize(600, 600);
ui->gridLayout->addWidget(container,1,1);
myProcess = new QProcess(container);
myProcess->setWorkingDirectory("../../simpleX11Embed/build");
myProcess->start("./simpleX11Embed", QStringList() << "-into" << QString().setNum(container->winId()));
ui->stopButton->setEnabled(true);
connect(myProcess, SIGNAL(finished(int)), this, SLOT(enableStartButton()));
}
void MainWindow::stopPrototype() {
myProcess->close();
}
void MainWindow::enableStartButton() {
container->close();
ui->label_screenshot->show();
ui->stopButton->setEnabled(false);
ui->startButton->setEnabled(true);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Second Widget :
#include "simpleX11Embed.h"
MainWindow::MainWindow(QWidget *parent) : QX11EmbedWidget(parent) {
QTextEdit *textBrowser = new QTextEdit();
textBrowser->setFocusPolicy(Qt::StrongFocus);
textBrowser->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *widlayout = new QVBoxLayout(this);
widlayout->addWidget(textBrowser);
}
int main(int argc, char *argv[]){
QApplication app(argc, argv);
if(app.arguments().count() > 2)
if (app.arguments()[1] == "-into") {
QString windowId(app.arguments()[2]);
MainWindow window;
window.embedInto(windowId.toULong());
window.show();
return app.exec();
}
MainWindow w;
w.show();
return app.exec();
}
I'm attaching the source too.
To get on my error when executing the SimpleX11Container:
press start button, press tab, press tab again, type anything int the text edit, press stop button and press the right arrow to change tab, then the keyboard stop.