#include "mainwindow.h"
#include <QWindow>
#include <QObject>
#define HEIGHT 708
#define FTP_HEIGHT 60
#define WIDTH 196
#include <pthread.h>
#include <mqueue.h>
#include <QtWidgets/qwidget.h>
#include <qwindow.h>
#include <qwindowdefs.h>
#define HELLOTEST "/home/Documents/5.1example/rasterwindow/rasterwindow"
void *wait_for_id(void * arg);
extern MainWindow *Container;
MainWindow
::MainWindow(QWidget *parent
){
qDebug()<< "MainWindow";
ApplicationProcess = NULL;
getDisplayProperties(&max_width,&max_height);
setWindowMinimumSizes(max_width - 300,HEIGHT - 100);
setWindowMaximumSizes(max_width,max_height);
createActions();
createMenus();
mainwindow->setMinimumSize(min_width,min_height);
mainwindow->setMaximumSize(max_width,max_height);
setCentralWidget(mainwindow);
pl.setColor(pl.Background,Qt::white);
mainwindow->setAutoFillBackground(true);
mainwindow->setPalette(pl);
appwindow = new ApplicationWindow (min_width - WIDTH ,min_height - (FTP_HEIGHT + 105),max_width - WIDTH,max_height - (100 +FTP_HEIGHT ) );
display = appwindow->createApplicationWindow();
vWidget->setLayout(vLayout);
vLayout->addWidget(display);
vLayout->setSpacing(1);
mainLayout ->addWidget(vWidget);
mainwindow ->setLayout(mainLayout);
vLayout->setContentsMargins(0,0,0,0);
display->setContentsMargins(0,0,0,0);
mainwindow->setContentsMargins(0,0,0,0);
pthread_t tid;
if (-1 == pthread_create(&tid,NULL,wait_for_id,NULL)){
perror("pthread_create");
}else{
qDebug()<<"thread create success";
}
}
void MainWindow::getDisplayProperties(int* width,int* height )
{
int x = 0,y = 0;
rec = D.geometry();
rec.getRect(&x,&y,width,height);
}
void MainWindow::setWindowMinimumSizes(int min_width,int min_height)
{
this->min_width = min_width;
this->min_height = min_height;
printf("Minimum Height is %d\n",min_height);
}
void MainWindow::setWindowMaximumSizes(int max_width,int max_height)
{
this->max_width = max_width;
this->max_height = max_height;
}
void MainWindow::createActions()
{
HelloTestAct
= new QAction(tr
("&HelloTest"),
this);
connect(HelloTestAct,SIGNAL(triggered()),this,SLOT(Launch_Hello_Test()));
connect(this,SIGNAL(send_winid(int)),this,SLOT(launch_app(int)));
}
void MainWindow::Launch_Hello_Test()
{
qDebug() << "Launch_Hello_Test";
pthread_t tid;
ApplicationProcess
= new QProcess(display
);
//connect( ApplicationProcess,SIGNAL(readyReadStandardError()),logwindow,SLOT(readStandardError()));
//connect( ApplicationProcess,SIGNAL(readyReadStandardOutput()),logwindow,SLOT(readStandardOutput()));
connect(ApplicationProcess,
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(finish
(int,
QProcess::ExitStatus)));
ApplicationProcess->start(executable, arguments);
}
void * wait_for_id( void *arg)
{
struct mq_attr mqAttr;
char buffer[1024];
mqd_t msgid;
int ret_val;
int winid;
mqAttr.mq_maxmsg = 10;
mqAttr.mq_msgsize = 512;
if(mq_unlink("/embed6")<0)
qDebug()<<"Init unable to unlink";
else
qDebug()<<"Init unlink success";
msgid = mq_open("/embed6",O_RDWR|O_CREAT,0777,&mqAttr);
if(-1 == msgid){
perror("mq_open");
return NULL;
}else{
qDebug()<< "mq_open success";
}
ret_val = mq_receive(msgid,buffer,sizeof(buffer),NULL);
if(-1 == ret_val) {
qDebug() << "mq_receive ret_val(Err) = "<< ret_val;
}
else {
qDebug() << "window id received is :"<< buffer;
mq_close(msgid);
winid = atoi(buffer);
Container->embed_window(winid);
if(mq_unlink("/embed6")<0)
qDebug()<<"unable to unlink";
else
qDebug()<<"unlink success";
}
}
void MainWindow ::embed_window(int id)
{
emit send_winid(id);
}
void MainWindow::launch_app(int id)
{
qDebug()<<"In launch_app";
WId winid = (WId) id;
display->setLayout(vl);
QWindow *wind = QWindow::fromWinId(winid);
window = createWindowContainer(wind,display,0);
//vl->addWidget(window);
}
void MainWindow
::finish(int,
QProcess::ExitStatus) {
qDebug()<<"finish";
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(HelloTestAct);
}
MainWindow :: ~MainWindow()
{
}
#include "mainwindow.h"
#include <QWindow>
#include <QObject>
#define HEIGHT 708
#define FTP_HEIGHT 60
#define WIDTH 196
#include <pthread.h>
#include <mqueue.h>
#include <QtWidgets/qwidget.h>
#include <qwindow.h>
#include <qwindowdefs.h>
#define HELLOTEST "/home/Documents/5.1example/rasterwindow/rasterwindow"
void *wait_for_id(void * arg);
extern MainWindow *Container;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
qDebug()<< "MainWindow";
ApplicationProcess = NULL;
QWidget* mainwindow = new QWidget();
getDisplayProperties(&max_width,&max_height);
setWindowMinimumSizes(max_width - 300,HEIGHT - 100);
setWindowMaximumSizes(max_width,max_height);
createActions();
createMenus();
mainwindow->setMinimumSize(min_width,min_height);
mainwindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
mainwindow->setMaximumSize(max_width,max_height);
setCentralWidget(mainwindow);
QPalette pl ;
pl.setColor(pl.Background,Qt::white);
mainwindow->setAutoFillBackground(true);
mainwindow->setPalette(pl);
vLayout = new QVBoxLayout();
mainLayout = new QHBoxLayout();
vWidget = new QWidget();
appwindow = new ApplicationWindow (min_width - WIDTH ,min_height - (FTP_HEIGHT + 105),max_width - WIDTH,max_height - (100 +FTP_HEIGHT ) );
display = appwindow->createApplicationWindow();
vWidget->setLayout(vLayout);
vLayout->addWidget(display);
vLayout->setSpacing(1);
mainLayout ->addWidget(vWidget);
mainwindow ->setLayout(mainLayout);
vLayout->setContentsMargins(0,0,0,0);
display->setContentsMargins(0,0,0,0);
mainwindow->setContentsMargins(0,0,0,0);
mainwindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
display->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
pthread_t tid;
if (-1 == pthread_create(&tid,NULL,wait_for_id,NULL)){
perror("pthread_create");
}else{
qDebug()<<"thread create success";
}
}
void MainWindow::getDisplayProperties(int* width,int* height )
{
int x = 0,y = 0;
QRect rec;
QDesktopWidget D;
rec = D.geometry();
rec.getRect(&x,&y,width,height);
}
void MainWindow::setWindowMinimumSizes(int min_width,int min_height)
{
this->min_width = min_width;
this->min_height = min_height;
printf("Minimum Height is %d\n",min_height);
}
void MainWindow::setWindowMaximumSizes(int max_width,int max_height)
{
this->max_width = max_width;
this->max_height = max_height;
}
void MainWindow::createActions()
{
HelloTestAct = new QAction(tr("&HelloTest"),this);
connect(HelloTestAct,SIGNAL(triggered()),this,SLOT(Launch_Hello_Test()));
connect(this,SIGNAL(send_winid(int)),this,SLOT(launch_app(int)));
}
void MainWindow::Launch_Hello_Test()
{
qDebug() << "Launch_Hello_Test";
pthread_t tid;
ApplicationProcess = new QProcess(display);
QString executable(HELLOTEST);
QStringList arguments;
//connect( ApplicationProcess,SIGNAL(readyReadStandardError()),logwindow,SLOT(readStandardError()));
//connect( ApplicationProcess,SIGNAL(readyReadStandardOutput()),logwindow,SLOT(readStandardOutput()));
connect(ApplicationProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(finish(int,QProcess::ExitStatus)));
ApplicationProcess->start(executable, arguments);
}
void * wait_for_id( void *arg)
{
struct mq_attr mqAttr;
char buffer[1024];
mqd_t msgid;
int ret_val;
int winid;
mqAttr.mq_maxmsg = 10;
mqAttr.mq_msgsize = 512;
if(mq_unlink("/embed6")<0)
qDebug()<<"Init unable to unlink";
else
qDebug()<<"Init unlink success";
msgid = mq_open("/embed6",O_RDWR|O_CREAT,0777,&mqAttr);
if(-1 == msgid){
perror("mq_open");
return NULL;
}else{
qDebug()<< "mq_open success";
}
ret_val = mq_receive(msgid,buffer,sizeof(buffer),NULL);
if(-1 == ret_val) {
qDebug() << "mq_receive ret_val(Err) = "<< ret_val;
}
else {
qDebug() << "window id received is :"<< buffer;
mq_close(msgid);
winid = atoi(buffer);
Container->embed_window(winid);
if(mq_unlink("/embed6")<0)
qDebug()<<"unable to unlink";
else
qDebug()<<"unlink success";
}
}
void MainWindow ::embed_window(int id)
{
emit send_winid(id);
}
void MainWindow::launch_app(int id)
{
qDebug()<<"In launch_app";
QVBoxLayout *vl = new QVBoxLayout;
WId winid = (WId) id;
display->setLayout(vl);
QWindow *wind = QWindow::fromWinId(winid);
window = createWindowContainer(wind,display,0);
//vl->addWidget(window);
}
void MainWindow::finish(int,QProcess::ExitStatus)
{
qDebug()<<"finish";
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(HelloTestAct);
}
MainWindow :: ~MainWindow()
{
}
To copy to clipboard, switch view to plain text mode
#include "rasterwindow.h"
#include<mqueue.h>
#include <stdio.h>
#include<qwindow.h>
#include<qwindowdefs.h>
int main(int argc, char **argv)
{
struct mq_attr mqAttr;
char buffer[512];
mqd_t msgid;
int ret_val;
int winid_int;
WId winid ;
mqAttr.mq_maxmsg = 10;
mqAttr.mq_msgsize = 512;
QGuiApplication app(argc, argv);
RasterWindow window;
qDebug()<<"before mq_open";
winid = window.winId();
qDebug()<<"window id is :"<< winid;
winid_int = (int) winid;
qDebug()<<"window id int :"<< winid;
msgid = mq_open("/embed6",O_RDWR);
if(-1 == msgid){
perror("mq_open");
return NULL;
}else{
qDebug()<<"mq_open success";
}
sprintf(buffer,"%d",winid_int);
ret_val = mq_send(msgid,buffer,strlen(buffer)+1,1);
if(-1 == ret_val)
perror("mq_receive");
else {
qDebug () << "window id sent is"<< buffer;
mq_close(msgid);
}
window.show();
return app.exec();
}
#include "rasterwindow.h"
#include<mqueue.h>
#include <stdio.h>
#include<qwindow.h>
#include<qwindowdefs.h>
int main(int argc, char **argv)
{
struct mq_attr mqAttr;
char buffer[512];
mqd_t msgid;
int ret_val;
int winid_int;
WId winid ;
mqAttr.mq_maxmsg = 10;
mqAttr.mq_msgsize = 512;
QGuiApplication app(argc, argv);
RasterWindow window;
qDebug()<<"before mq_open";
winid = window.winId();
qDebug()<<"window id is :"<< winid;
winid_int = (int) winid;
qDebug()<<"window id int :"<< winid;
msgid = mq_open("/embed6",O_RDWR);
if(-1 == msgid){
perror("mq_open");
return NULL;
}else{
qDebug()<<"mq_open success";
}
sprintf(buffer,"%d",winid_int);
ret_val = mq_send(msgid,buffer,strlen(buffer)+1,1);
if(-1 == ret_val)
perror("mq_receive");
else {
qDebug () << "window id sent is"<< buffer;
mq_close(msgid);
}
window.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks