Starting Frame.jpgnew display.jpg

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

Qt Code:
  1. #include "gui_cctv_wrapper.hpp"
  2. #include "gui_image.hpp"
  3.  
  4.  
  5.  
  6. gui_cctv_wrapper::gui_cctv_wrapper(QWidget *parent) :
  7. QWidget(parent)
  8. {
  9. CCTV_Process = new QProcess(this);
  10.  
  11. CCTV_Process->setProgram(CCTV_Process_Path);
  12.  
  13. CCTV_Process->start();
  14. connect(this,SIGNAL(started()),this,SLOT(Thread_Slot()));
  15. emit started();
  16. //delay(20000);
  17. //CCTV_Container->setStyleSheet("background-color: black");
  18.  
  19. }
  20.  
  21. /// Class destructor
  22. gui_cctv_wrapper::~gui_cctv_wrapper(void)
  23. {
  24. try
  25. {
  26. this->CCTV_Process->close();
  27. delete CCTV_Process;
  28. //LOG_DEBUG << "Deleting Process";
  29. //
  30.  
  31. // Nothing to tidy. Smart pointers will take care of the dynamically
  32. // created classes.
  33. }
  34. catch(...)
  35. {
  36. // prevent exceptions from destructor
  37. }
  38.  
  39. }
  40.  
  41. void gui_cctv_wrapper::createprocess()
  42. {
  43. //QPalette pl ;
  44. //pl.setColor(Qt::black);
  45. /// delay 160 ms so that windows can find the ID
  46. delay(200);
  47. id = NULL;
  48. do
  49. {
  50. id = (WId)FindWindow(NULL,L"LXC CCTV Monitor");
  51. delay(100);
  52. }while(id == NULL);
  53.  
  54. if(id != NULL)
  55. {
  56. Window = QWindow::fromWinId(id);
  57. //Window->requestActivate();
  58.  
  59. qDebug() << Window->geometry().width();
  60. qDebug() << Window->geometry().height();
  61. QSize* Size = new QSize(1900,680);
  62. //Window->setMinimumSize(*Size);
  63. //->setStyleSheet("border: 1px solid green");
  64. Window->setSurfaceType(QWindow::OpenGLSurface);
  65. CCTV_Container = QWidget::createWindowContainer(Window, this, Qt::FramelessWindowHint);
  66. qDebug() << CCTV_Container->geometry().width();
  67. qDebug() << CCTV_Container->geometry().height();
  68. //CCTV_Container->setMinimumSize(*Size);
  69. //CCTV_Container->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  70. CCTV_Container->setStyleSheet("background-color: blue");
  71. //CCTV_Container->setPalette(p1);
  72. CCTV_Container->setMinimumSize(1696,1066);
  73. CCTV_Container->autoFillBackground();
  74. qDebug() << CCTV_Container->geometry().width();
  75. qDebug() << CCTV_Container->geometry().height();
  76. QVBoxLayout *Layout2 = new QVBoxLayout(this);
  77. Layout2->setMargin(0);
  78. Layout2->addWidget(CCTV_Container);
  79. this->setLayout(Layout2);
  80. update();
  81. }
  82.  
  83.  
  84. }
  85.  
  86. void gui_cctv_wrapper::delay(int n)
  87. {
  88. QTime dieTime = QTime::currentTime().addMSecs(n);
  89. while( QTime::currentTime() < dieTime )
  90. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  91. }
  92.  
  93. void gui_cctv_wrapper::paintEvent(QPaintEvent* aEvent)
  94. {
  95. Opt.init(this);
  96. QPainter p(this); /* First line of most paintEvents. */
  97. style()->drawPrimitive(QStyle::PE_Widget,&Opt,&p,this);
  98. }
  99.  
  100. void gui_cctv_wrapper::resizeEvent(QResizeEvent * Event)
  101. {
  102. this->QWidget::resizeEvent(Event);
  103. update();
  104. }
  105.  
  106. void gui_cctv_wrapper::Thread_Slot()
  107. {
  108. moveToThread(&Thread);
  109. connect(&Thread,SIGNAL(started()),this,SLOT(createprocess()));
  110. Thread.start();
  111. }
To copy to clipboard, switch view to plain text mode 

gui_cctv_wrapper.hpp

Qt Code:
  1. #ifndef GUI_CCTV_WRAPPER_HPP_
  2. #define GUI_CCTV_WRAPPER_HPP_
  3.  
  4. #include <QWidget>
  5. #include <QProcess>
  6. #include <QGridLayout>
  7. #include <QWindow>
  8. #include <QTime>
  9. #include <QCoreApplication>
  10. #include <memory>
  11. #include <QThread>
  12. #include <QResizeEvent>
  13. #include <QSize>
  14.  
  15. #include "windows.h"
  16. //#include "gui_configuration.hpp"
  17.  
  18. //#include "common/logging/log_client.hpp"
  19.  
  20. class gui_cctv_wrapper : public QWidget
  21. {
  22. Q_OBJECT
  23. public:
  24. explicit gui_cctv_wrapper(QWidget *parent = 0);
  25. ~gui_cctv_wrapper();
  26. void delay(int n);
  27.  
  28. void paintEvent(QPaintEvent* aEvent);
  29.  
  30. void resizeEvent(QResizeEvent * Event);
  31. signals:
  32. void started();
  33.  
  34. public slots:
  35. void Thread_Slot();
  36. void createprocess();
  37.  
  38. private:
  39. QWindow * Window;
  40. WId id;
  41. QThread Thread;
  42. //std::unique_ptr< QProcess > CCTV_Process;
  43. QProcess * CCTV_Process;
  44.  
  45. QString CCTV_Process_Path = "C:\\Software\\lxc\\bin\\bin\\lxc_cctv.exe";
  46. //std::unique_ptr<QWidget> CCTV_Container;
  47. QWidget * CCTV_Container;
  48. };
  49.  
  50. #endif // GUI_CCTV_WRAPPER_HPP_
To copy to clipboard, switch view to plain text mode 

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.