"Failed to setup resampler" when starting QAudioSink - c++

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)

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.

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.

How to use LibVLC with Qt 5

I'm trying to use LibVLC in a Qt 5 program to open a VLC instance and play a video.
The following code comes from https://wiki.videolan.org/LibVLC_Tutorial/
I'm using Linux.
.pro :
TEMPLATE = app
TARGET = projectLoic
INCLUDEPATH += . vlc
QT += widgets
# Input
HEADERS +=
SOURCES += main.cpp
LIBS +=-lvlc
main :
#include <vlc/vlc.h>
#include <QApplication>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
// Load the VLC engine
inst = libvlc_new(0, NULL);
// Create a new item
m = libvlc_media_new_path (inst, "/home/........mp3");
// Create a media player playing environement
mp = libvlc_media_player_new_from_media (m);
// play the media_player
libvlc_media_player_play (mp);
return app.exec();
}
The compilation is fine. But the program immediatly crashes when I build it (with Qt Creator). Any idea?
Many thanks
Many things could cause this crash. The best is to get VLC source code to trace back the issue. Passing the option '--verbose=2' when initializing libVLC can help as well.
In my case the cause of the crash was due to this bug in the ubuntu package of vlc:
https://bugs.launchpad.net/ubuntu/+source/vlc/+bug/1328466
When calling libvlc_new() vlc modules and their dependent libraries are loaded into memory. The qt module of LibVLC was searching for Qt4 shared objects instead of Qt5 (manually installed).
The solution was to rebuild the module cache which was outdated an pointing to Qt4 binaries. You can reset it on the command line:
sudo /usr/lib/vlc/vlc-cache-gen -f /usr/lib/vlc/plugins/
Or pass to vlc the option:
--reset-plugins-cache
I have never used this library, but Are you using exactly this code?
m = libvlc_media_new_path (inst, "/home/........mp3");
This path may be the problem.
What distribution of Linux are you using?
I ran into this same problem with Qt5 and LibVLC, and the primary cause (Ubuntu 12.04 LTS and 14.04 LTS), was that LibVLC was loading the qt4 interface plugin, which conflicted with Qt5. If you check your call stack, you'll most likely see that at a Qt4 library was being loaded, causing the crash.
If this is the problem, there are only 3 options (tested with LibVLC 2.2 and Qt5 on Ubuntu 12.04 and 14.04 LTS 64 bit).
The first (worst) is to delete the qt4 user interface plugin. You can test this is the problem by moving and running and then setting it back. Deleting will break your regular VLC player most likely.
Second option is to create a copy of the plugins directory and set that in your runtime path using VLC_PLUGIN_PATH, environment variable. but I've had trouble getting that to work without changing the original plugin path folder also (which will break your VLC player unless you modify your shortcuts, etc. to also set VLC_PLUGIN_PATH.
The third option, and what I ended up doing, was to custom build my own static LibVLC binary with a few edits to the source code so that it will not load the qt4 interface plugin installed with VLC. You can follow these steps to do this.
1) Download VLC Source Code for your platforms distribution.
http://download.videolan.org/pub/videolan/vlc/
Make sure you download the version matching your distribution. For
example, match the VLC version to what is installed with Ubuntu.
2) Extract source code to folder
3) Install dependencies for the OS distribution
sudo apt-get build-dep vlc
4) Modify src/modules/bank.c
Edit the module_InitDynamic function
Add the following code at the top of the function:
// HACK TO DISABLE QT4 PLUGIN
if(strstr(path, "qt4") != NULL)
return NULL;
// END HACK
3) From terminal
./bootstrap
./configure --disable-qt --disable-skins2 --enable-xcb --prefix=/home/$USER/vlc-custom_build_output_folder_name
./make
./make install
4) Copy/Save the resulting files in the install folder.
Then just link against this library instead.