Opening external application and embed it without opening application out of application
-
How can I embed application like a widget in application that I created.
I searched about this and found couple of implementation. I don't know anything about this and never read about this. But I want to make something working browser.This one is first answer that I found about this topic
mainwindow.cpp
QString prog = "C:/Program Files/Mozilla Firefox/firefox.exe"; QStringList arg; arg << "google.com"; QString workDir = "C:/Program Files/Mozilla Firefox/"; program->startDetached(prog, arg, workDir, 0); WId hWnd = 0; while (hWnd == 0) { hWnd = (WId) FindWindowW(NULL, L"C:/Program Files/Mozilla Firefox/firefox.exe"); } window = QWindow::fromWinId(hWnd); container = QWidget::createWindowContainer(window, ui->mdiArea); QMdiSubWindow *subWindow = new QMdiSubWindow(); subWindow->setWidget(container); subWindow->setAttribute(Qt::WA_DeleteOnClose); subWindow->setWindowTitle("Program 1"); ui->mdiArea->addSubWindow(subWindow); container->show();
In mainwindow.h
Added necessary headers and these variables in privateprivate: WId id; QProcess *program; QWindow *window; QWidget *container;
second answer
mainwindow.cpp
browserLocation = "C:/Program Files/Mozilla Firefox/firefox.exe"; mainWidget = new QWidget(this); browserWidget = new QWidget(mainWidget); mainLayout = new QVBoxLayout(mainWidget); QLabel *label = new QLabel(mainWidget); label->setText("Is label showing up?"); proc = new QProcess(this); proc->setProgram(browserLocation); proc->start(); qDebug()<<"Started with pid "<<proc->pid(); WId id = this->winId(); QWindow *window = QWindow::fromWinId(id); browserWidget = QWidget::createWindowContainer(window,mainWidget); mainLayout->addWidget(label); mainLayout->addWidget(browserWidget); mainWidget->setLayout(mainLayout); setCentralWidget(mainWidget);
In mainwindow.h
added necessary headers with these variables in private:private: QString browserLocation; QProcess *proc; QWidget *mainWidget; QVBoxLayout *mainLayout; QWidget *browserWidget;
Both of the programs run and open firefox as seperate window. And our application doesn't show up. On both way , application doesn't die until we force it to with either from task manager or by rerunning program.
I couldn't find anything working
I came to know that Qtwebkit isn't that much supported by big services and I have been using MINGW :
https://forum.qt.io/topic/132551/using-qwebkit-for-windows-with-mingw -
@Thank-You said in Opening external application and embed it without opening application out of application:
I came to know that Qtwebkit isn't that much supported by big services:
Use MSVC and Qt WebEngine
-
@Christian-Ehrlicher
Sorry I forgot to mention for MINGW. I will update question.
But I am not actually sure that we can embed another application inside widget without opening it as application but it is only my thought 😂😂. Can we do it????. -
@Thank-You
@Christian-Ehrlicher is suggesting that a much more Qt solution is not to try to run some external Firefox browser program but rather to use Qt WebEngine which is a Chromium engine you can use as a widget in your application. It's an awful neater. However, it is true that under Windows it means you would need to use MSVC toolchain instead of MinGW. -
@Thank-You
Probably depends on the application, don't know whether there are issues with FireFox, and I don't use Windows.Since you appear to say you got one or other of your code examples from somewhere, why don't you reference where that was? If that was an example of embedding, surely that code would have been tested as working, I imagine.
A post from 2009, https://www.qtcentre.org/threads/23290-Embedded-browser-in-QT, answers
Is it possible to create a QWindow (or something like it) and embed a browser in this window?
The browser could be chosen by the user, IE, Firefox, Chrome...
with
The answer is "it depends but in general no".
I don't know if that still applies....
-
@JonB
It's limereport
https://limereport.ru/en/index.phpAlmost a year ago I built it with mingw and stuck with it.
Thanks for your suggestion.whether there are issues with FireFox
No I don't mean firefox specific. Any browser.
Although this is out of context but,
If you have used edge , then each tab is considered as separate window and usingALT + TAB
it shows a lots of windows opened. If I got this solution I could use it there too and make it as unified so it would be easier with it too. -
@Thank-You
I updated my previous post with some (potentially bad) news.I don't see anything in your "LimeReport" which has anything to do with embedding an external application into a Qt UI/widget, so i don't know what connection to your application is. Since it appears that you have its source code, why aren't you integrating it into your code (it says "Pure Qt4/Qt5 compatible code") rather than something about trying to run Firefox?
I would start out Googling for
qt embed external application
to assess what might be possible. -
-
@Thank-You said in Opening external application and embed it without opening application out of application:
It doesn't have any connection with embedding.
Then I don't know what relevance it has to your question.
As a whole main purpose is to make application run browser without opening real browser window.
I quoted a potential answer of "No, not for Firefox", but suggested what you should Google for to investigate embedding external applications into Qt. (There are further specific hits for
qt embed firefox
.) Find one of those, see if it works, see if it can applied to your situation or not. -
@JonB
I have seen many of posts about this topic.
https://stackoverflow.com/questions/33699258/qt-5-5-embed-external-application-into-qwidget
All of these go out of my head. I haven't learned about these topic before.I will try installing msvc and will try to work with it.
HOPING for the best -
@Thank-You
You already havewindow = QWindow::fromWinId(hWnd); container = QWidget::createWindowContainer(window, ui->mdiArea);
The solution at that stackoverflow link is merely to add
window->setFlags(window->flags() | Qt::FramelessWindowHint);
I have no idea whether that is relevant to your situation, just saying that is all they are adding.