How to embed a native window into QML component? - c++

I'm developing a cross-platform SIP application based on PJSUA2 for the core and QtQuick for the GUI.
PJSUA2 provides an API for displaying the user's capture devices as well as the remote party video stream. Such an API exposes a native window handler for a given video. The native window handler is platform-specific (HWND on Windows, NSView* on Mac, etc).
I'd like to embed this native window into a specific QML component, let's say a Rectangle.
Is that possible?
FYI: I'm using MacOS Sierra 10.12.6, PJSIP 2.7 with SDL backend and Qt 5.9.2. But I'd like to make it work on both Windows and MacOS.

You cannot. You can't even include a QWidget inside a Qt Quick Item.
To give you somehting to chew, you can take a look at https://github.com/vlc-qt/vlc-qt .
They offer QWidgets and QtQuick Items that allow to use VLC to play videos.
They use a window handle (HWND) for the widget (https://github.com/vlc-qt/vlc-qt/blob/master/src/core/MediaPlayer.cpp#L217).
But for Qt Quick they copy each video frame into a QSGNode (https://github.com/vlc-qt/vlc-qt/blob/master/src/core/VideoStream.cpp#L111 and https://github.com/vlc-qt/vlc-qt/blob/master/src/qml/rendering/VideoNode.cpp#L32).

Related

Copy text selection to clipboard in Windows using Qt and C++

I would like to allow the user to insert a selected text from any source or application into my Qt application using the middle mouse button.
This functionality is already available with the help of the QCliboard class on operating systems with X11 Window System. According to the Qt documentation, this does not work on Windows because Windows does not support the global mouse selection.
Is there a way to make this functionality available in Windows as well? Can this be achieved with a Qt and C++ implementation? Is there possibly a C++ library that I could integrate which offers this functionality?

Use Apple Pencil through Qt framework

I want to port my Qt application to use the apple pencil on an iPad Pro. Currently, my app uses QTabletEvent to draw to a QGraphicsScene using a Wacom enabled device. I'm planning on trying to handle events from apple pencil with objective-c++ and feed it into Qt's event system. I've never used objective-c++, what are some good tutorials to try to solve this problem? I'm specifically looking for how to pass events from objective-c++ to Qt.
You can call any Qt code from methods in Objective C++ code. You can easily create new events and post them to your application.

How to create VST plugin using MFC?

I already have an MFC gui standalone program. What should be done to make it a VST 2.x plugin? (It would a lot of rework if I use VSTGUI/win32/qt/etc - or is it possible/appropriate to use VSTGUI?)
Which VST interfaces (gui and others) should I implement for VST 2.x gui plugin?
You are worried about the GUI of a VST when in fact you should be worried about the structure of the rest of your code. VST 2.x hands you a HWND for a frame, all you have to do is create a child window that hosts your GUI. MFC, raw WIN32 - does not matter.
However, the real 'problem' is in the rest of the VST 2.x interface. You should study this interface and learn how it works. Then you'll be able to assess if your code is in the correct structure to easily interface as a VST plugin.
you just need to slave your window code to the HWND you're given. The easiest way is just to slave your whole window using SetParent, and then implement MFC like you would in a normal app.
However, there are no knobs, nor digital or analog readouts. Even with MFC if you want to make a polished VST interface you'll be rolling your own UI code either way.
So it's almost worth it just to handle the WM_XXXX messages and do the windowing and drawing all yourself.

Embedding another Window as a QWidget

I'm currently working on a project that uses Allegro for rendering, input, etc. However I would like to add a GUI to my project using something like Qt. The problem is that Allegro does not support using a Window not created by allegro for rendering/input, it needs to create the window itself. I was thinking of using Qt to make the UI, and then creating a window normally using allegro, and then somehow embedding the allegro window into the Qt application.
Allegro provides the HWND handle to the window its using. Is there anyway to embed the allegro window into a Qt ui using its HWND handle?
You need the QWinHost class from the Qt/MFC Migration Framework. The code is 3-clause BSD licensed. You only need two files: qwinhost.h and qwinhost.cpp, available here.
It does exactly what you need, and works on both Qt 4 and 5.

QT How to embed an application into QT widget

In our project we have three independent applications, and we have to develop a QT control application that controls these three applications. The main window will be seperated to three sub windows - each one display another one application.
I thought to use QX11EmbedWidget and QX11EmbedContainer widgets, but two problems with that:
The QX11Embed* is based on X11 protocol and I dont know if it's supported on non-x11 systems like Windows OS.
Since QT 5 these classes are not existing, and the QT documentation doesn't mention why.
So that I dont know whether to use it or not - I'll be happy to get an answers.
In addition, I see that the QT 5.1 contains QWidget::createWindowContainer(); function that in some posts it looks like this should be the replacement to the X11Embed. Can anyone please explian me more how can I use this function to create a QT widget that will run another application (a Calculator for example) inside its?
I have searched a lot in Google, and didn't find answers to my Qs.
Can anyone please help me? Am I on the right way?
Thanks!
If all three independent applications are written with Qt, and you have their source, you should be able to unify them just through the parenting of GUI objects in Qt.
http://qt-project.org/doc/qt-4.8/objecttrees.html
http://qt-project.org/doc/qt-4.8/widgets-and-layouts.html
http://qt-project.org/doc/qt-4.8/mainwindows-mdi.html
If you don't have access to them in that way, what you are talking about is like 3rd party window management. It is kind of like writing a shell, like Windows Explorer, that manipulates the state and the size of other window applications.
Use a program like Spy++ or AutoIt Spy for Windows and the similar ones for other OS's, and learn the identifying markings of your windows you want to control, like the class, the window title, etc. Or you can launch the exe yourself in a QProcess::startDetached() sort of thing.
http://qt-project.org/doc/qt-5.1/qtcore/qprocess.html#startDetached
Then using the OS dependent calls control the windows. The Qt library doesn't have this stuff built in for third party windows, only for ones under the QApplication that you launched. There are a lot of examples of doing things like this by AutoHotKey, or AHK. It is a scripting language that is made for automating a lot of things in the windows environment, and there is port for Mac as well (though I haven't tried the mac port myself).
So in the end you are looking at finding your window probably with a call like this:
#include <windows.h>
HWND hwnd_1 = ::FindWindow("Window_Class", "Window Name");
LONG retVal = GetWindowLongA(hwnd_1, GWL_STYLE); // to query the state of the window
Then manipulate the position and state of the window like so:
::MoveWindow(hwnd_1, x, y, width, height, TRUE);
::ShowWindow(hwnd_1, SW_SHOWMAXIMIZED);
You can even draw widgets on top of the windows you are controlling if you set your window flags correctly for the windows you are manipulating.
transparent QLabel with a pixmap
Cannot get QSystemTrayIcon to work correctly with activation reason
Some gotchas that come up in Windows when doing all of this, is finding out the quirks of the Windows UI when they set the Display scaling different from what you expect, and if you want to play nice with the Task bar, and handling all the modal windows of your programs you are manipulating.
So overall, it is do-able. Qt will make a nice interface for performing these commands, but in the end you are looking at a lot of work and debugging to get it in a beautiful, reliable, window manager.
Hope that helps.
I never tried it myself, but from the docs in Qt 5.1 I would try QWindow::fromId(WId id), which gives you a QWindow, which should be embeddable with createWindowContainer:
QWindow * QWindow::fromWinId(WId id) [static] Creates a local
representation of a window created by another process or by using
native libraries below Qt.
Given the handle id to a native window, this method creates a QWindow
object which can be used to represent the window when invoking methods
like setParent() and setTransientParent(). This can be used, on
platforms which support it, to embed a window inside a container or to
make a window stick on top of a window created by another process.
But no guarantee. :-)