Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Embedding One Qt Application into another on Windows [SOLVED]

    General and Desktop
    1
    2
    1546
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      ion_knight last edited by

      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), it works but creates a strange white border on the right and bottom side (even though a Qt stylesheet should be making the background 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_wrapper.cpp

      @#include "gui_wrapper.hpp"
      #include "gui_image.hpp"

      gui_wrapper::gui_wrapper(QWidget *parent) :
      QWidget(parent)
      {
      Process = new QProcess(this);

      Process->setProgram(Process_Path);
      
      Process->start();
      emit started();
      //delay(20000);
      //Container->setStyleSheet("background-color: black");
      

      }

      /// Class destructor
      gui_wrapper::~gui_wrapper(void)
      {
      try
      {
      this->Process->close();
      delete 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_wrapper::createprocess()
      {

      /// delay 160 ms so that windows can find the ID
      delay(2000);
      WId id = NULL;
      do
      {
          id = (WId)FindWindow(NULL,L"Monitor");
      }while(id == NULL);
      
      
      if(id != NULL)
      {
          QWindow * Window = QWindow::fromWinId(id);
          Window->requestActivate();
          Container = QWidget::createWindowContainer(Window);
      
          QGridLayout *Layout2 = new QGridLayout(this);
          Layout2->setMargin(0);
          Layout2->addWidget(Container);
          this->setLayout(Layout2);
      }
      

      }

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

      void gui_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_wrapper::Thread_Slot()
      {
      moveToThread(&Thread);
      connect(&Thread,SIGNAL(started()),this,SLOT(createprocess()));
      Thread.start();
      }
      @

      gui_wrapper.hpp

      @#ifndef GUI_WRAPPER_HPP_
      #define GUI_WRAPPER_HPP_

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

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

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

      class gui_wrapper : public QWidget
      {
      Q_OBJECT
      public:
      explicit gui_wrapper(QWidget *parent = 0);
      ~gui_wrapper();

      void delay(int n);
      
      void paintEvent(QPaintEvent* aEvent);
      

      signals:
      void started();

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

      private:
      QThread Thread;
      //std::unique_ptr< QProcess > Process;
      QProcess * Process;

      QString Process_Path = "C:\\Software\\lxc\\bin\\bin\\cctv.exe";
      //std::unique_ptr<QWidget> Container;
      QWidget * Container;
      

      };

      #endif // GUI_WRAPPER_HPP_
      @

      1 Reply Last reply Reply Quote 0
      • I
        ion_knight last edited by

        After debugging this for a long while, a friend of mine thought of something I didn't see. When creating the window container you can give it options called window hints, applying these didn't work when passing them into the createwindowcontainer as parameters. But instead if you include this parameter into the embedded application during form creation you will no longer see any white border with "Qt::framelesswindowhint".

        E.g.

        : QMainWindow(Qt::framelesswindowhint).

        1 Reply Last reply Reply Quote 0
        • First post
          Last post