Need to embed LibreOffice window into Qt Widget

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
danylo_nevidomiy
Posts: 2
Joined: Thu Nov 02, 2023 3:59 pm

Need to embed LibreOffice window into Qt Widget

Post by danylo_nevidomiy »

I need to embed the LibreOffice window in QWidget.

The user dom19191 in the subject viewtopic.php?t=109793 has already done this, but there is no information on how he did it.

I have Qt 5.15.2, Libreoffice 7.3.6.2, linux based on Debian x86_64, kernel 5.15.0-33-generic
LibreOffice 7.3.6.2 on Debian 9
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Need to embed LibreOffice window into Qt Widget

Post by JeJe »

As its looking like no-one else here may know... you could message him perhaps... or post in that other thread, when he'll more likely get messaged about the new post than see this different thread.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
danylo_nevidomiy
Posts: 2
Joined: Thu Nov 02, 2023 3:59 pm

Re: Need to embed LibreOffice window into Qt Widget

Post by danylo_nevidomiy »

I partially managed to solve this problem, but now I'm getting behavior that I don't understand.I am running Libreoffice using this code:

Code: Select all

Reference< XComponentContext > xComponentContext = bootstrap();
    Reference< XMultiComponentFactory > rServiceManager =   xComponentContext->getServiceManager();
    Reference< XInterface  > office=rServiceManager->createInstanceWithContext(OUString( RTL_CONSTASCII_USTRINGPARAM(desktopServiceName) ),
                                                      xComponentContext );
    Reference < XComponentLoader > componentLoader(office, UNO_QUERY );
    xComponentLoader  = componentLoader;
    Sequence<PropertyValue> loadProps(4);
    loadProps[0].Name = OUString::createFromAscii("Hidden");
    loadProps[0].Value = Any(hidden);
    loadProps[1].Name = OUString::createFromAscii("UpdateDocMode");
    loadProps[1].Value = Any(sal_Int16(com::sun::star::document::UpdateDocMode::FULL_UPDATE));
    loadProps[2].Name = OUString::createFromAscii("Silent");
    loadProps[2].Value = Any(true);
    loadProps[3].Name = OUString::createFromAscii("AsTemplate");
    loadProps[3].Value = Any(true);
OUString sDocUrl = "";
    osl::FileBase::getFileURLFromSystemPath(OUStringFromStd(document),sDocUrl);
    Reference< XComponent > composantWriter = xComponentLoader->loadComponentFromURL(
                sDocUrl, OUString::createFromAscii("_blank"), 23, loadProps);
    Reference< XModel> xModel(composantWriter, UNO_QUERY_THROW);
    Reference< XController> xController = xModel->getCurrentController();
    Reference< XFrame> xFrame xFrame = xController->getFrame();
    Reference< XWindow> xWindow xWindow = xFrame->getContainerWindow();
    Reference<XSystemDependentWindowPeer> xWindowPeer(xWindow, UNO_QUERY);
    Any hwnd = xWindowPeer->getWindowHandle(Sequence<sal_Int8>(0), com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW);
    SystemDependentXWindow dependWindow = hwnd.get<SystemDependentXWindow>();
    int Id = dependWindow.WindowHandle;
    winId = Id;
Where WinId is a variable that stores the window id in the object property. Next, I want to embed the LibreOffice editor window into my Qt application using this code:

Code: Select all

QWindow *window = QWindow::fromWinId(writer->getWinId());
    QWidget *widget = QWidget::createWindowContainer(window);
    QVBoxLayout *layout = new QVBoxLayout(ui->editorWidget);
    layout->addWidget(widget);
    ui->editorWidget->setLayout(layout);
Where writer is the object that launched the Libreoffice editor and saved its id. Now, when I try to embed the editor window, I get two duplicate editors: one in my application and one in its original window, which work mirrored and both freeze.


P.S. I wrote an email to the author of the entry I referred to earlier, but unfortunately he does not respond
LibreOffice 7.3.6.2 on Debian 9
Post Reply