Missing file when deploying Qt app on Mac OSX - macos

I'm trying to deploy a Qt application on Mac OSX so I'm running this command:
macdeployqt Example.app
It mostly seems to work as the executable grows in size so I assume the relevant plugins and libraries are being added. However, in the end macdeployqt outputs this error message:
ERROR: no file at "/usr/local/pgsql/lib/libpq.5.dylib"
Does anybody know what this file is? Do I need to install something to make it work?

The documentation states: SQL driver plugins are deployed if the application uses the QtSql module. The macdeployqt tool does not know which plugins your application uses, and tries to deploy all of them. Your application does not link directly with any of the plugins, so there's no way to tell what it uses merely by looking at the executable. The macdeployqt tool would need to parse the code of your application, or use potentially breakable heuristics to scan for sql driver name strings. It's a shortcoming of the macdeployqt tool.
A temporary workaround would be to move the unused plugins out of the plugins/sqldrivers folder in QtSdk.
Note: The Example.app is not an executable. It is an application bundle -- a folder with stuff in it and you can inspect its contents in the usual way: from the shell, or via Finder by right-clicking on the application bundle.

Related

Is There Macdeployqt for QT Command Line Executable Binary Without App Bundle?

I'm trying to build a command line tool on Mac that doesn't result in .app bundle.
When I run make release, it just gives an executable file since it's a command line tool for terminal.
I understand that macdeployqt lets you package all the necessary files for .app to run without qt installed on another machine.
Is there similar tool for just binary executable?
When I pass the executable to macdeployqt, I get "ERROR: Could not find bundle binary for ...".
macdeployqt is run against an existing .app bundle and handles most of the library collection and install_name_tool business to make the bundle deployable. Even if you were to utilize this tool, you would end up customizing the binary's install_name info manually to suit your purpose.
https://github.com/SCG82/macdylibbundler will bundle an app and fix up the install names/rpaths. Disclaimer: I'm the developer.

How to deploy a Qt application that uses SQLite on OS X

I am trying to deploy a Qt application that uses SQLite on OS X.
I simply ran the command:
macdeployqt MyApplication.app -dmg
and I get the following error:
ERROR: no file at "/opt/local/lib/mysql55/lib/libmysqlclient.18.dylib"
I already read about SQLite plugin on this link but I could not understand how it works.
Note:
I have a folder: ......./Qt5.3.2/5.3/clang_64/plugins/sqldrivers/
that contains:
libqsqlite.dylib
libqsqlite_debug.dylib
and some other libs related to other sql drivers.
Any idea how can I solve this?
Thanks
As SGaist answer here:
macdeployqt deploys all the plugins by default since it doesn't know
which one you'll be using.
Note that you can build the .dmg in two steps, first run macdeployqt,
then remove all the unused Sql plugins and then create the image.
It means that if I am not using MySQL in my application I can just ignore this error message.

macdeployqt - "file not found" - missing qml file from qrc

I am trying to deploy an app using Qt (version 5.6.1) for OS X (10.11.5) with macdeployqt tool. Just after running qmake and make the app seems to work fine. However, when I try to use macdeployqt I am experiencing some errors. The qml files become nonexistent, and I get following result:
QQmlApplicationEngine failed to load component
qrc:/qml/main.qml:-1 File not found
I've tried to run macdeployqt from its directory (as some people on the web suggested) and even tried some funky build of this tool provided by third party... I am aware of macqtdeploy qmldir option (it didn't change anything). Does anybody know what exactly macdeployqt is doing to those resources? Why they are missing?

Trace dylib loading on Mac OSX

I'm trying to build a Qt-based application on Mac OSX, and something in my application bundle is pulling in a Qt library from /Library rather than from the application bundle.
I've done this successfully in the past, so I know about using install_name_tool to link applications and libraries to the bundle versions of libraries. I've done this, but I must be missing something. I've tried setting DYLD_PRINT_LIBRARIES, but I'm not really sure how this helps: I can see which Qt library is being pulled in from /Library first (QtXml), but I don't know which file in the bundle is pulling in this library.
Is there some trick to tracing back which file is loading a particular library?
Use otool utility to see what libraries are used by your app and where the app expects to find them:
otool -L yourApp.app/Contents/MacOS/yourApp

Automatically include Qt libraries in the .app bundle deploying on Mac

I am using Qt Creator to deploy my Qt application. On Mac, I'd like to include the required Qt libraries in the .app bundle. Is there any way to do it automatically using Qt Creator? Should I do it using the command-line? In that case, how should I do it?
The macdeployqt command line tool will add all the necessary Qt libraries that your Qt project references.
If you require any other, 3rd party libraries, you'll need to copy these manually and set the paths to them using the install_name_tool command.
You can check which libraries your application references using the otool command. For example: -
otool -L MyApplication.app/Contents/MacOS/MyApplication
For Qt Creator, I tend to write a script that adds the necessary libraries and calls macdeployqt and then under Projects, add a build step which calls the script.
An example script that would just add the Qt libraries would look something like this: -
#!/bin/bash
pwd
echo Copying QT libraries...
macdeployqt ./MyApplication.app
You can simply run macdeployqt foo.app. Qt Creator does not support this feature off-hand either. However, you can inject custom commands into your process in the QtCreator project settings.
It does not support QML just yet though. There are patches under codereview where it is coming. See the following link for details:
https://codereview.qt-project.org/#q,status:open+project:qt/qttools,n,z
Note: macdeployqt should not be used for usual development and debug! It should be only used when deploying. Otherwise, it is executed each time for building even if you just recompile the code due to a minor change for testing. This can slow down that process, but as for deploying, it should be alright.
On QT6 I was able to do it entirely within QT Creator:
In Projects/Build, add a custom build step after 'make' (probably only want to do this for your 'release' configuration):
Command: %{Qt:QT_HOST_PREFIX}/bin/macdeployqt
Arguments: %{ActiveProject:BuildConfig:Path}/%{ActiveProject:Name}.app - qmldir=%{ActiveProject:NativePath}
Working Directory: %{buildDir}
I was able to test it by airdropping the resulting .app onto my test machine.
reference: https://doc.qt.io/qt-6/macos-deployment.html#macdeploy

Resources