compiled QMLs incompatible between minor version changes - c++

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

Related

"Failed to setup resampler" when starting QAudioSink

I'm porting some QtMultimedia code from Qt 5.15 to 6.4.1. The following program, when built with Qt 6.4.1 on Windows:
int main (int argc, char *argv[]) {
QCoreApplication a(argc, argv);
QAudioDevice device = QMediaDevices::defaultAudioOutput();
QAudioFormat format = device.preferredFormat();
QAudioSink *output = new QAudioSink(device, format);
output->start();
return a.exec();
}
Fails to start the audio output, printing the following message:
qt.multimedia.audiooutput: Failed to setup resampler
The equivalent code in Qt5 (using QAudioDeviceInfo and QAudioOutput) seems to run fine. What am I missing here?
Apparently, it's a bug in Qt 6.4.1 on Windows, where, as the user johnco3 discovered in that forum post, for some reason QAudioSink is looking for a DLL named "mfplat.dll.dll" when it should be looking for "mfplat.dll" (it adds an extra ".dll" suffix).
The correctly named version of this DLL lives in the Windows system directory (e.g. C:\Windows\System32\mfplat.dll), so there are a couple of workaround until the bug is fixed:
Go back to Qt 6.4.0, apparently it's a new issue in 6.4.1, or
Copy mfplat.dll to somewhere in the DLL path then rename it to "mfplat.dll.dll":
Either copy it to the application executable's directory and rename it there, or
Create some folder somewhere, copy and rename it there, then add that folder to the PATH environment variable.
It's a somewhat silly bug, but alas. At least the workaround exists and can be easily undone when the bug is eventually fixed.
See also:
https://bugreports.qt.io/browse/QTBUG-108383 (johnco3's bug report)
https://bugreports.qt.io/browse/QTBUG-108669 (a duplicate bug report; I filed it before I found any of this)

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.

Qt5: Preventing another instance of the application doesn't work anymore...!

I am using Qt5 on a Windows7 platform.
My application is some kind of TCP server listening on port 8002, so I only want one instance of it.
In order to prevent multiple instances of my application, I use(d) the code below (found here on StackOverflow):
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSharedMemory sharedMemory;
sharedMemory.setKey("TcpServer-Key");
if(sharedMemory.create(1) == false)
{
QMessageBox::warning(NULL, "Warning!", "Another instance already running!");
a.exit(); // exit already a process running
return 0;
}
...
Well, the code above used to work just fine, until I upgraded my Qt to 5.5.1.
Now, with Qt 5.5.1, I don't see the warning message-box anymore!... When I try to start another instance, the running app disappears/stops and a new app is started!!!
Please help, what should I do? But don't tell me to switch back to Qt 5.4.x :(
Remark: I forgot to mention that I set & used msvc2012 compiler during tests (not minGW, as I wasn't able to build log4cxx for it).
UPDATE: Could it be an issue related to the antivirus installed on that PC (at the office, i.e. McAfee)?... Now I'm at home (AVG antivirus and MinGW compiler and log4cxx removed) and I am unable to reproduce the above described issue :(
I finally discovered where the problem was... and it's not the antivirus to be blamed :)
When I upgraded the Qt (Creator v3.6.0) to the newest version (5.5.1), there is a setting in Tools->Options->Build&Run named [Stop app before building]... that was set to Current project or something. Hence, the Qt Creator was killing the old instance before launching a new one(!).
Setting this option to None solved the issue.
So, it seems the code was just fine, antivirus was fine, yet launching the app from within Qt Creator was somehow restricted to only one instance :)
I decided to share this, maybe it will be helpful for other folks as well.
Remark : I checked again and now I can confirm: That setting didn't exist before, at least not in Qt Creator v3.3.2.

CodeBlocks Qt HelloWorld.exe has stopped working (C++)

I'm a beginner "programmer", and I'm using quotation marks because I'm THAT green.
Windows 7 64-bit
Code::Blocks 13.12
OpenCV 2.4.10
Qt 4.8.5
I've been thrown into single-handedly creating a pretty big (for me) piece of software that uses OpenCV and mingw to track movement of a few different markers and calculate (and accurately guess...) a lot of things. I'm almost done, but and I have to incorporate some GUI elements into it, most importantly a dialog window with which you can look for files (came up yesterday). So I've tried setting up Qt with Code::Blocks and creating a basic Hello World app. I've set up the env Path variable, I've pointed the linker and compiler search directories where they should be. It still doesn't work.
#include <QApplication>
#include <QFont>
#include <QPushButton>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
This is the thing I am trying to run. Compiles fine, no errors or warnings. But when I run it, it immediatly stops working, as in "Qt.exe has stopped working" and process returns -1073741819... it crashes the moment it tries to do something Qt-specific (QApplication...)
I added a simple cout << "Hello world"; before QApplication app(argc, argv);, and it displayed in the console, and then stopped working.
Even when I bare the code down to
QApplication app(argc, argv);
return app.exec();
it still crashes the same way.
My first question... what could possibly be the problem? I ran out of ideas and Google doesn't want to help me either. I've tried using the Qt Creator, and it worked fine, but I couldn't get it to work... it'd just print "Naci" into the console, regardless of what project I tried to run, and I have no idea what "Naci" is and where it came from.
PS: And another question. Is it possible to create a console app that at one point calls a function that has the QDialog window and gets filename from it?
edit:
I'm trying to run examples attached to Qt release. They all give me undefined reference to vtable errors and none of the solutions I've found around work. Jesus... this is not friendly towards new people
edit2: I'm going to rebuild and reconfigure Qt... on my 1ghz netbook it's probably going to take a while...
I reconfigured Qt and then rebuilt it via MingW again. Even though after 6 hours compilation failed, it did enough... and now Qt works with Code::Blocks. Odd. I've done that before, no idea why this time it worked and the last time it didn't.
For those who don't know how to do that, run command line (if on Windows), go to the main folder of Qt (the one with include, bin, lib (etc) folders, in my case C:\Qt\4.8.5), type configure.exe (use configure.exe -help to see available parameters) and after it's done configuring just go mingw32-make and wait for an hour or ten.

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.