How to use qt webassembly in qml application - qt

I am beginner in web assenbly and I want to use qt webassembly in qml application. I use emsdk 1.38.30-64bit to compile qml application and it compile successfully but when I use emsdk 1.38.30-64bit with thread flag in my browser I get downloading/compiling. what is my mistake and how should I solve this problem?

Qt multi-thread support is still quite in development, a single thread application should be in general fine for QML apps, the QML engine is still single threaded. Try also newer emscripten compilers, but even in my extensive testing with versions 1.39+ multi-thread was an issue. Quick note if you want to test your QML app in the browser, you can use Felgo WebEditor for quick snippet testing https://felgo.com/web-editor or you can test our fully fledged web IDE https://ide.felgo.com

Related

Qt error with reMarkable tablet app

I have a reMarkable tablet , which I mostly love except for the lack of linux support (surprising given it is a linux-based OS). However, I've managed to find a version of a linux application that is now unofficial. This github is actually a Qt docker app, but if you look in the code for the 'Dockerfile' you can find where to download the app, which is apparently still on the server even though there's not a link from the main web page. Anyway, I downloaded it and got it mostly working, figuring out a few dependencies based on same Dockerfile code. But, I can't seem to get file dialogs to work, which is the main reason for using the app.
The error I get is:
ERROR: No native FileDialog implementation available.
Qt Labs Platform requires Qt Widgets on this setup.
Add 'QT += widgets' to .pro and create QApplication in main().
I'm not a Qt developer, so I'm lost. I'd love to get this to work. Thanks.
In the .pro file of you project you should add this line QT += widgets
or just add widgets to the line with QT += ...
Qt can use native file dialogs on some platforms, and will fall back to its own implementation if none is available. But that requires that the application is built including the QtWidgets module, and using a QApplication.
If you don't have the source code of the app and a possiblity to rebuild it, there's no chance to fix this from a binary

Using Qt classes natively in an Android application

The Android application I am about to work on has the UI in Java and the non-UI functionality in C++ that would be accessed via JNI. The C++ code uses some non-UI Qt classes. I am thinking I will spawn a thread in JNI_OnLoadthat essentially will instantiate and run QCoreApplication. Any subsequent JNI call will simply post an event to this thread. Is this possible? Regards.
What you want to do is definitely possible but a bit more difficult than it seems initially.
If you build your app end to end in Qt there's a lot of functionality you get for free from their framework that allows it to run on Android and a lot of that functionality/plumbing is wrapped up in their UI. So if you're not using their UI there's extra work that you need to do.
On Android their UI framework basically creates a native Activity and then uses that activity as a wrapper for the app. If you look at the low-level source for their UI thats what's happening on Android and it's what allows the Qt app to access local resources, the network, OS facilities, etc.
Without the Activity wrapper, your app will only be able to do simple, in-memory operations that require no OS, file system, or network access and also won't be able to make use of other Qt libraries(eg Qt5Sql, Qt5Core, etc).
Here's what we had to do to make this work in our java app:
Create a proxy wrapper Activity for Qt to use that shares the base
context of your app.
Create a QtActivityDelegate.
Set the proxy activity and delegate using the native Qt android
libraries. eg QtNavite.setActivity.
Instantiate and set a DexClassLoader using the same native Qt android libraries.
Load any Qt libraries using System.loadLibrary(..). Please note that the libraries need to be present on the file system already. This part was a big pain for us.
For your Qt Code, make sure you have proper wrappers written so that they can be used via jni. We ended up using swig to auto-generate java wrappers for our code.
You can find out more about swig here: http://swig.org/
After all that you should be able to use your Qt class/library from within a native Android app.
Painful but definitely possible!

Is there any way to use QtWebEngine without OpenGL?

I'm trying to get QtWebEngine running on a VM and am having difficulties. According to the answer to this question:
Eventually I realised that OpenGL 3.3 wouldn't work easily on virtual machines .. yet. I had to boot from ubuntu usb and work from there by installing latest mesa 3d package.
Is there a way to get QtWebEngine to work without OpenGL? I'm not directly using any OpenGL calls, nor do I need any 3d capabilities. I just want to embed a QWebEngineView to display dynamic HTML pages. I'm guessing this should be possible since Chrome works on the same VM without an issue.
I don't think there is a way to use the Qt WebEngine without OpenGL. It is not very explicitly said in the documentation, but here's what I understood from what I found.
About Chromium
As it is said here, QtWebEngine integrates chromium's fast moving web capabilities into Qt. Plus, it is Chromium that allows the manipulation of OpenGL via the Qt Quick scene graph (source) :
Chromium is tightly integrated to the Qt Quick scene graph, which is
based on OpenGL ES 2.0 or OpenGL 2.0 for its rendering. This provides
you with one-pass compositing of web content and all the Qt Quick UI.
The integration to Chromium is transparent to developers, who just
work with Qt and JavaScript.
It is also said that both the render process and the GUI process should share an OpenGL context :
Because the render process is separated from the GUI process, they
should ideally share an OpenGL context to enable one process to access
the resources uploaded by the other, such as images or textures.
About the Qt WebEngine itself
We just talked about the Qt's GUI : in fact, the Qt WebEngine is not dependent of this GUI (page rendering and JavaScript execution are separated from the GUI process into the Qt WebEngine process), but remember that if you want your application to work, you will need to share an OpenGL context between both processes. In particular, this is achieved by default with a QSurfaceFormat, which has a OpenGLContextProfile accessible by the function QSurfaceFormat::profile(). Now, we look back at the Qt WebEngine platform notes which states :
If a new default QSurfaceFormat with a modified OpenGL profile has to
be set, it should be set before the application instance is declared,
to make sure that all created OpenGL contexts use the same OpenGL
profile.
On OS X, if the default QSurfaceFormat is set after the application
instance, the application will exit with qFatal(), and print a message
that the default QSurfaceFormat should be set before the application
instance.
If we look at the source code of Qt, calls to OpenGL are made in several important files, like qtwebengine\src\core\web_engine_context.cpp or qtwebengine\src\webengine\api\qtwebengineglobal.cpp. Moreover, I also found calls to OpenGL in functions from the sources in qtwebengine\src\3rdparty\chromium\, so I suspect that Chromium needs to call OpenGL functions sometimes.
In short
The Qt WebEngine is using Chromium (which doesn't necessarily use OpenGL) and also Qt GUI, which uses an OpenGL context which has to be shared by the Web Engine. Thus, my conclusion is that you can't use the Qt WebEngine without OpenGL.
I had the same problem on my VM environment trying to start an application that uses QtWebEngine and it crashed.
I will add this answer as a reference - although Sergey Khasanov mentioned it already in the comment above
Use Software Qt Quick2DRenderer - see https://doc.qt.io/QtQuick2DRenderer/
To do that, simply set the environment variable:
export QMLSCENE_DEVICE=softwarecontext
then restart your application. It might still complain about
libEGL warning: GLX/DRI2 is not supported
libEGL warning: DRI2: failed to authenticate
but (in my case) it finally worked!

Modify Qt's shared library code while application starts

I'm trying to create some kind of a server which allows me to start Qt's applications on remote machine via web browser.
I'm wondering it is possible to change/hide some symbols from Qt library (I thought about QApplication or QCoreApplication) without making any changes in code of application (I assume that it is already compiled and uses Qt shared library) and compiling my whole tailor-made Qt libs?
The reason why I need to do this is because I want to install my own specific EventFilter to QApplication and also be able to push my own created events to Qt application.
It also would be great if the solution could be used on all platforms :D
P.S. I know that it will not be possible I could subclass QApplication and modify all Qt apps to use my derived class but I would like to do this more craftily. ;-)
The tool GammaRay does all kinds of injecting code into Qt methods at runtime to attach and debug running Qt applications. You might want to have a look at its code base to see how it is done.

QT for cross platform plugin development?

I have a pre-existing application, that calls out into a plugin library. I want the plugin library to be developed in Qt, and to be able to display a Qt UI.
However, when I attempt to create a QWidget it complains that the QApplication needs to be created first.
Is it not possible to use Qt to develop cross platform plugins?
E.g. a netscape plugin for Chrome or Firefox. I do not, and cannot, control the app's main loop.
As explain in the Qt documentation, any GUI application using Qt needs a QApplication to be created into main thread since it is containing all signal engine and event loop.
There is Qt/MFC Migration Framework that can help you to build plugins if the main application where the plugin is laoded is Win32 or Mfc. Qt/MFC Migration Framework

Resources