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

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?

Related

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.

Running OSX Bundle via Open

I'm trying to make an OSX bundle using CMake/CPack on OSX that involves OpenCV and Qt (although I don't think those dependencies matter at this point). Everything compiles and the bundle is created fine, and I have a script that modifies the necessary library paths such the executable I'm making works if I run it from the Terminal within the bundle. The problem I'm having is if I try to run the MyApp.app file via the open command or by simply double clicking the app it gives me the error:
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/
I've seen other solutions to other LSOpenURLsWithRole() errors involving modifying permissions, but that hasn't helped me. Also, this error code is an "unknown error" so I'm not sure how to proceed.
The solution for this ended up being that the libcocoa.dylib library was not finding the requisite libraries. See Building OSX App Bundle for a thorough answer on the subject. otool -L is your best friend.

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

Missing file when deploying Qt app on Mac OSX

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.

Deploying Qt Frameworks with Mac app and usage of otool

I have a problem deploying Qt frameworks with my Mac app, and I hope some will have a clue why I get this error, when I run the app on clean Mac, i.e. not a developer Mac.
OS: 10.7 .2 and using XCode
Error msg:
Library not loaded: #loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Clearly something is wrong since the QtXml is referenced from /../Frameworks/../Frameworks, which doesn’t exists.
This is the set up: I have a dylib that uses QtCore and QtXml (not by my choosing, but for now I need those two frameworks), the dylib is used in a NSBundle, which is loaded by the main app, the bundle is located in the resource folder. The dylib is moved by Copy Files Build Phase to the folder Contents/Frameworks and with otool the install_name is set to (as stated by http://doc.qt.digia.com/4.3/deployment-mac.html):
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
#loader_path/../Frameworks/QtXml.framework/Versions/4/QtXml
then the Qt frameworks are moved to Contents/Frameworks and the install_name of the is set to:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
and for the QtXml
#executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml
with reference to QtCore:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Now when I run the app on the developer mac it clearly works since Qt is installed, but when moved to a clean mac I get the error msg, readable in the Console app.
I’ve tried to change the executable_path to loader_path, but this didn’t work.
I have no idea what I’m doing wrong or why it won't for, and have not been able to find anything on Google, of course I could be looking at the wrong places. Any ideas how to fix this problem?
This is the entire error message:
MainApp: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle
“Library” couldn’t be loaded because it is damaged or missing
necessary resources."
(dlopen_preflight(/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/
Contents/MacOS/Library): Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from: /Users/ someUser /Downloads/
MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found) UserInfo=0x107c5d5d0
{NSLocalizedFailureReason=The bundle is damaged or missing necessary
resources., NSLocalizedRecoverySuggestion=Try reinstalling the
bundle.,
NSFilePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library,
NSDebugDescription=dlopen_preflight(/Users/someUser
/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library):
Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:
/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found,
NSBundlePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle,
NSLocalizedDescription=The bundle “Library” couldn’t be loaded because
it is damaged or missing necessary resources.}
On the development mac everything works because the Qt libraries are installed. On any mac you ship the app to, though, this likely won't be the case. The Qt suite comes with a tool called macdeployqt to fix this. So in a terminal, after you've compiled your application, do something like:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app
Note that it can also be used to create a .dmg file for shipping everything together:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app -dmg
Once you've done that, the .app directory or .dmg file can be given to someone else without Qt installed to use and run as they normally would.
The one caveat is that the next time you try to run it on your developer machine, it may complain about multiple shared libraries installed. So once you've copied it else where in order to distribute it, remove the entire .app directory and let qtcreator (or whatever) rebuild it.
UPDATE
As stated compiling QT to static libs is the way to go. With the release of Mavericks (10.9) we need to codesign frameworks as well (http://furbo.org/2013/10/17/code-signing-and-mavericks/), and with QT4.8.5 there are some issues (https://bugreports.qt-project.org/browse/QTBUG-32896). Even with suggested fixes I still had some issues when running the app on a clean machine. Therefore, I ended up with compiling Qt5.2 to staticlibs, link them in the app, and codesign them.
OLD
Problem sovled, I moved the Qt-frameworks into the app bundle in Contents/Frameworks and with otool set the path to #executable_path/../Frameworks, i.e. moved it out of my library bundle. Yes the solution is simple, but I'm still not sure why the library executable couldn't find the frameworks when using #loader_path.
The best solution would probably be to use a static library and not wrap it in a bundle...you learn everyday ;)

Resources