PDA

View Full Version : Embedding One Qt Application into another on Windows



Ion
2nd December 2014, 17:48
1077510776

Currently having trouble trying to figure out how best to approach this, currently I have a program that embeds another Qt Application using creatingwindowcontainer and fromwinid. However the program I wish to embed doesn’t start off in GUI mode (and instead starts off as a console application and only generates the form once it has received a message over socket comms).

So having trouble embedding this application from inside the other Qt Application (using QProcess), the embedding works fine however it doesn't fill the whole area and instead leaves the left and button sides in white(even when a stylesheet should be making it black) .

Below is my code for starting the process can anyone see any problems with what i’m trying to do, if anyone has any suggestions that would be great.

gui_cctv_wrapper.cpp


#include "gui_cctv_wrapper.hpp"
#include "gui_image.hpp"



gui_cctv_wrapper::gui_cctv_wrapper(QWidget *parent) :
QWidget(parent)
{
CCTV_Process = new QProcess(this);

CCTV_Process->setProgram(CCTV_Process_Path);

CCTV_Process->start();
connect(this,SIGNAL(started()),this,SLOT(Thread_Sl ot()));
emit started();
//delay(20000);
//CCTV_Container->setStyleSheet("background-color: black");

}

/// Class destructor
gui_cctv_wrapper::~gui_cctv_wrapper(void)
{
try
{
this->CCTV_Process->close();
delete CCTV_Process;
//LOG_DEBUG << "Deleting Process";
//

// Nothing to tidy. Smart pointers will take care of the dynamically
// created classes.
}
catch(...)
{
// prevent exceptions from destructor
}

}

void gui_cctv_wrapper::createprocess()
{
//QPalette pl ;
//pl.setColor(Qt::black);
/// delay 160 ms so that windows can find the ID
delay(200);
id = NULL;
do
{
id = (WId)FindWindow(NULL,L"LXC CCTV Monitor");
delay(100);
}while(id == NULL);

if(id != NULL)
{
Window = QWindow::fromWinId(id);
//Window->requestActivate();

qDebug() << Window->geometry().width();
qDebug() << Window->geometry().height();
QSize* Size = new QSize(1900,680);
//Window->setMinimumSize(*Size);
//->setStyleSheet("border: 1px solid green");
Window->setSurfaceType(QWindow::OpenGLSurface);
CCTV_Container = QWidget::createWindowContainer(Window, this, Qt::FramelessWindowHint);
qDebug() << CCTV_Container->geometry().width();
qDebug() << CCTV_Container->geometry().height();
//CCTV_Container->setMinimumSize(*Size);
//CCTV_Container->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);
CCTV_Container->setStyleSheet("background-color: blue");
//CCTV_Container->setPalette(p1);
CCTV_Container->setMinimumSize(1696,1066);
CCTV_Container->autoFillBackground();
qDebug() << CCTV_Container->geometry().width();
qDebug() << CCTV_Container->geometry().height();
QVBoxLayout *Layout2 = new QVBoxLayout(this);
Layout2->setMargin(0);
Layout2->addWidget(CCTV_Container);
this->setLayout(Layout2);
update();
}


}

void gui_cctv_wrapper::delay(int n)
{
QTime dieTime = QTime::currentTime().addMSecs(n);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEve nts, 100);
}

void gui_cctv_wrapper::paintEvent(QPaintEvent* aEvent)
{
QStyleOption Opt;
Opt.init(this);
QPainter p(this); /* First line of most paintEvents. */
style()->drawPrimitive(QStyle::PE_Widget,&Opt,&p,this);
}

void gui_cctv_wrapper::resizeEvent(QResizeEvent * Event)
{
this->QWidget::resizeEvent(Event);
update();
}

void gui_cctv_wrapper::Thread_Slot()
{
moveToThread(&Thread);
connect(&Thread,SIGNAL(started()),this,SLOT(createprocess() ));
Thread.start();
}



gui_cctv_wrapper.hpp


#ifndef GUI_CCTV_WRAPPER_HPP_
#define GUI_CCTV_WRAPPER_HPP_

#include <QWidget>
#include <QProcess>
#include <QGridLayout>
#include <QWindow>
#include <QTime>
#include <QCoreApplication>
#include <memory>
#include <QThread>
#include <QResizeEvent>
#include <QSize>

#include "windows.h"
//#include "gui_configuration.hpp"

//#include "common/logging/log_client.hpp"

class gui_cctv_wrapper : public QWidget
{
Q_OBJECT
public:
explicit gui_cctv_wrapper(QWidget *parent = 0);
~gui_cctv_wrapper();
void delay(int n);

void paintEvent(QPaintEvent* aEvent);

void resizeEvent(QResizeEvent * Event);
signals:
void started();

public slots:
void Thread_Slot();
void createprocess();

private:
QWindow * Window;
WId id;
QThread Thread;
//std::unique_ptr< QProcess > CCTV_Process;
QProcess * CCTV_Process;

QString CCTV_Process_Path = "C:\\Software\\lxc\\bin\\bin\\lxc_cctv.exe";
//std::unique_ptr<QWidget> CCTV_Container;
QWidget * CCTV_Container;
};

#endif // GUI_CCTV_WRAPPER_HPP_

If anyone has any ideas what is going wrong that would be great, I have also uploaded two images one before the app is embedded and one for after with a red box to highlight the problem more clearly. Hope you someone can help. Thanks in Advance.