Qt WebEngineView: Problem with loading a WebGL project (exported from Unity) - c++

I'm trying to download a WebGL project (exported from Unity 2018.3.14f1) in Qt WebEngineView (Qt 5.12.0)
For an example, WebGL project was created in Unity 2018 - an empty scene without objects (camera only) - Screenshot: Unity project
and exported to the WebGL Assembly (applied .gzip compression, build size 2.3 MB) - Screenshot: Unity build settings
The Qt project was take from Qt's library of examples ("WebEngine Widgets Minimal Example").
#include <QApplication>
#include <QWebEngineView>
QUrl commandLineUrlArgument()
{
const QStringList args = QCoreApplication::arguments();
for (const QString &arg : args.mid(1)) {
if (!arg.startsWith(QLatin1Char('-')))
return QUrl::fromUserInput(arg);
}
return QUrl(QStringLiteral("file:///F:/qt/test4Exp/index.html"));
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
view.setUrl(commandLineUrlArgument());
view.resize(1024, 750);
view.show();
return app.exec();
}
When you open a WebGL project in Chrome, everything loads very quickly (instantly) - Screenshot: WebGL project opened in Chrome
When you open WebGL in WebEngineView, the project takes a very long time to load (about 5-6 minutes) - Screenshot: WebGL project loading in WebEngineView
... but then it opens - Screenshot: WebGL project loaded in WebEngineView
The WebGL project is opened from a local drive. I have tried various options for Unity export parameters (brodil compression, code optimization, etc.). Tell me, what could be the problem? Can be applied to any option in the Assembly or in QCoreApplication::setAttribute ?
Below attached the project WebGL and Qt project
WebGL Project
Qt Project

The problem was solved after running the application from under exe file (not from under QtCreator).Everything works faster under exe file. Apparently the launch and initialization of the Unity engine is slowed down by QtCreator. When the application is running under exe web project launch in Web Engine View takes 2-3 seconds (on an old PC 7-9 seconds).

Related

compiled QMLs incompatible between minor version changes

I have a very simple QML app made with Qt 5.12 that runs fine on an linux embedded device. It consists of only one qml resource.
The device has recently gotten an OS update and now Qt 5.14 is available.
However the app now cannot run because of this error:
QQmlApplicationEngine failed to load component
qrc:/main.qml:-1 File was compiled ahead of time with an incompatible version of Qt and the original file cannot be found. Please recompile
It is a shame that with such a small version change i would need to keep both binaries for compatibility. I read some stuff on the internet saying to add CONFIG += qtquickcompiler to enable compilation before start, but it didn't change anything. The binary size is the same.
I haven't experienced such problems when not using QML, could even launch Qt5.9 compiled apps on Qt5.12 without problem.
That's basically all of my main.cpp:
int main(int argc, char *argv[])
{
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
The QML file itself only imports
import QtQuick 2.5
import QtQuick.Window 2.2
Is there anything I can do to preserve compatibility without storing a binary for each version I'm going to support? I could probably store the raw qml file right next to the binary and load it from the disk, but I'd rather keep it stored in the app resources.
I have confirmed it works fine when using QUrl::fromLocalFile, but I really don't like to have all the qml files lying around. Is there any way to store the qml as a resource AND not compile it? I know it's worse for start performance but I'm willing to accept it for compatibility
I think I found the way myself, actually the qtquickcompiler is enabled by default and removing it from the config resulted in a smaller binary size and launched properly on the newer Qt environment without having any local QML files (still using qrc) and also after clearing the QML cache.
CONFIG -= qtquickcompiler
In case no one has any better way to preserve compatibility, I'll mark this as accepted

Invisible text in QTextEdit

I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown. I added addApplicationFont and setFont calls below I found from web to the sample but it didn't help.
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFontDatabase::addApplicationFont("://Ubuntu-R.ttf");
app.setFont(QFont("Ubuntu", 11, QFont::Normal, false));
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
I am on Ubuntu 16.04 and run following commands on bash to make executable:
qmake -makefile
make
./part1
I want the app to use the default Ubuntu system font. I learned that Qt uses fontconfig for fonts but I don't know how to trace the issue.
Edit
I thought QFontDatabase::addApplicationFont("://Ubuntu-R.ttf") call referenced system font but instead it is referencing font app resource file. I don't have resource file so obviously it won't work.
.pro file is below(unmodified sample file):
QT += widgets
SOURCES = main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part1
INSTALLS += target
I tried to get system font using QFontDatabase but it didn't work:
app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
This doesn't do anything with any of enum values including QFontDatabase::GeneralFont
QFontDatabase database;
QStringList fam = database.families();
fam size is zero.
I will try to use embedded font next.
I don't know the exact reason of the problem but the reason was not configuring fontconfig dependency properly before building qt. I solved it by reconfiguring and recompiling qt again. You can find more details at qt forum.

Add Settings entry for iOS app using Qt 5.4

I have built an iOS 8.2 app using Qt 5.4. I want to add a user-entry field in the Settings app like a lot of other apps do, but I can't figure out how to do it. I tried the following (which doesn't work):
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
TDA::TapDisplaySingleton* mainClass =
new TDA::TapDisplaySingleton(&app);
QObject::connect(&app, SIGNAL(aboutToQuit()),
mainClass, SLOT(aboutToQuitApp()));
QGuiApplication::setOrganizationName("NASA Langley");
QGuiApplication::setOrganizationDomain("larc.nasa.gov");
QGuiApplication::setApplicationName("TAP Display");
QSettings settings;
settings.setValue("HOSTNAME", "localhost");
QTimer::singleShot(10, mainClass, SLOT(run()));
return app.exec();
}
When I fire the app up in the Simulator and open the Settings app, my entry does not appear. Does anyone know how to do this effectively in iOS using Qt?
As it turns out, Qt does provide a way to generate a Settings.bundle file for your app. You need to define a Root.plist and Root.strings file in advance and then add the following to your .PRO file:
SETTINGS_BUNDLE_DATA_ROOT.files += Root.plist
SETTINGS_BUNDLE_DATA_ROOT.path = Settings.bundle
SETTINGS_BUNDLE_DATA_LANG.files += Root.strings
SETTINGS_BUNDLE_DATA_LANG.path = Settings.bundle/en.lproj
QMAKE_BUNDLE_DATA += SETTINGS_BUNDLE_DATA_ROOT SETTINGS_BUNDLE_DATA_LANG
When your project is linked, the bundle will be created.
QSettings is only for storing settings in a persistent fashion. Adding settings to the iOS Settings application is outside of the scope of Qt. Look up "iOS Settings Bundle" for information on how to create those - eg https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html .

Qt5 WebKit not detecting NPAPI plugin

#include "mainwindow.h"
#include <QApplication>
#include <QtWebKit>
#include <QWebView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebView *view = new QWebView();
QWebSettings::PluginsEnabled;
view->load(QUrl("http://www.paulirish.com/demo/multi"));
view->show();
return a.exec();
}
I am trying to load a plugin in QtWebkit Webview but it isnt being loaded. I couldnt find the right path as mentioned Here, but it isnt loading. I have added Env. Variable QTWEBKIT_PLUGIN_PATH to System Variable & MOZ_PLUGIN_PATH was already in user variable, added by Foxit Reader. I tried placing the plugin dll file on both the directories corresponding to the Env. Variables but it isnt loading the plugin. After i palced the plugin in Moz_plugin_path, firefox was able to detect the plugin.
As for enabling the plugin in QTWebview i have tried using
QWebSettings::PluginsEnabled;
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled,true);
view->page()->settings()->PluginsEnabled;
but found success with none of them, I am using Windows 8.1 and Qt 5.2
You should set the QWebSettings::PluginsEnabled attribute. The way you are doing it, nothing is happening.
Enable the attribute with the following code:
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
Put this before your QWebView creation.
Refer to the documentation for more details:
QWebSettings Docs
i have been through exactly the same situation. what solved my problem was to install adobe flash player plugin for NPAPI. Modern web browsers like Google Chrome and Firefox are often distributed with builtin flash player plugin. So Chrome/Firefox works well does not ensure that you have the proper flash plugin installed properly systemwide, which is needed by Qt5WebKit to enable local plugin support for Flash content.
so, make sure the adobe flash player plugin for NPAPI is installed, and hope it would solve your problem.

Compiler can't find ui_xyz.h file

I've install Netbeans 7.2 and Qt 5 on Windows7. Everything compiles fine.
But recently when I create a Qt form and try to use it in this way:
New Project > C/C++ Qt Application > Finish
Right click on new Qt project > New > Qt Form > Finish
After saving ui file in Designer
This error appears:
newForm.h:11:24: fatal error: ui_newForm.h: No such file or directory
The content of main.cpp is :
#include <QGuiApplication>
#include "newForm.h"
int main(int argc, char *argv[])
{
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QGuiApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
I tried to manually create ui_xwz.h file and add it to my project. But I want it work automatically as same as before. How can I solve it?
I have a ridiculous solution, Maybe we should report it as a bug to Netbeans or Qt.
Go and active QtSVG and QtXml modules of your project and rebuild it. I tested this way and the problem vanished.