macdeployqt https://www.e-learn.cn/tag/macdeployqt zh-hans macdeployqt not copying plugins https://www.e-learn.cn/topic/3295919 <span>macdeployqt not copying plugins</span> <span><span lang="" about="/user/57" typeof="schema:Person" property="schema:name" datatype="">瘦欲@</span></span> <span>2020-01-24 10:40:07</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm developing a Qt-based application and when I use macdeployqt on the bundle, the Qt plugins are not copied to the bundle.</p> <p>However, if I run it a second time, they are. Additionally, "The svg icon plugin is deployed if the application uses the QtSvg module." is not fullfilled - my application does use QtSvg but the iconengines/* plugin is not copied.</p> <p>I tried running it with -verbose=3, and the last couple lines are:</p> <pre><code>Log: Created configuration file: "silverlock.app/Contents/Resources/qt.conf" Log: This file sets the plugin search path to "silverlock.app/Contents/PlugIns" </code></pre> <p>From what the last message says, it kind of seems that it intended to continue running, but didn't - almost as if it crashed.</p> <p>Why is this happening? macdeployqt has worked for me before without issue.</p> <p><strong>Using:</strong></p> <ul><li>Qt 4.6</li> <li>Qt Creator 2.0</li> <li>Leopard 10.5.8</li> </ul><br /><h3>回答1:</h3><br /><p>The problem lies at lines 355-365 of shared.cpp in the macdeployqt source:</p> <pre><code>while (frameworks.isEmpty() == false) { const FrameworkInfo framework = frameworks.takeFirst(); copiedFrameworks.append(framework.frameworkName); // Get the qt path from one of the Qt frameworks; if (deploymenInfo.qtPath.isNull() &amp;&amp; framework.frameworkName.contains("Qt") &amp;&amp; framework.frameworkDirectory.contains("/lib")) { deploymenInfo.qtPath = framework.frameworkDirectory; deploymenInfo.qtPath.chop(5); // remove "/lib/" } </code></pre> <p>The first framework/dylib name in your bundle that has "Qt" in its name is taken to determine the plugin path. Since the first framework/dylib name in my bundle was "QtSolutions_QtSingleApplication-2.6"... you get the picture. So I suppose a workaround is to rename the dylib to "qsa-2.6.dylib" or something.</p> <p>In a nutshell: make sure your framework and library names don't have "Qt" in them or you'll run into issues with macdeployqt.</p> <p>Hopefully this answer may help someone having the same issue.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/3454001/macdeployqt-not-copying-plugins</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c-0" hreflang="zh-hans">c++</a></div> <div class="field--item"><a href="/tag/macos" hreflang="zh-hans">macos</a></div> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Fri, 24 Jan 2020 02:40:07 +0000 瘦欲@ 3295919 at https://www.e-learn.cn macdeployqt and third party libraries https://www.e-learn.cn/topic/2991865 <span>macdeployqt and third party libraries</span> <span><span lang="" about="/user/64" typeof="schema:Person" property="schema:name" datatype="">久未见</span></span> <span>2019-12-29 14:58:26</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I've got an application project that depends on a couple of shared libraries that I have created myself. According to the Qt 4.6 documentation "Deploying an Application on Mac OSX":</p> <blockquote> <p>Note: If you want a 3rd party library to be included in your application bundle, then you must add an excplicit lib entry for that library to your application's .pro file. Otherwise, the macdeployqt tool will not copy the 3rd party .dylib into the bundle.</p> </blockquote> <p>I have added lib entries to my application's .pro file but the libraries that I have written do not get copied into the bundle when I execute macdeployqt. I have the following in my .pro file:</p> <pre><code>LIBS += -L../Libraries -lMyLib </code></pre> <p>Everything builds okay, its just when I try to run from the bundle that I run into problems i.e. "image not found" errors.</p> <p>Is there a bug in macdeployqt or do I have to something more to my .pro file?</p> <br /><h3>回答1:</h3><br /><p>badcat is correct that the Qt 4.6 documentation has a grossly inflated view of what is possible with <strong>macdeployqt</strong> tool.</p> <p>In my experience, the only things that are done by macdeployqt are:</p> <ol><li>Copy the Qt libraries into your app bundle in the foo.app/Contents/Frameworks/ directory</li> <li>Adjusts the link libraries of one binary, namely foo.app/Contents/MacOS/foo (must have same name as app bundle, even if you mention another binary in Info.plist)</li> </ol><p>So, for every other binary and library you want to deploy in your app bundle, you must do the following:</p> <ol><li><p>Run macdeployqt to enjoy its useful but feebly inadequate benefits</p> <p><code>macdeployqt &lt;path_to_your_nascent_app_bundle&gt;/foo.app</code></p></li> <li><p>Install your extra libraries manually</p> <p><code>cp &lt;original_library_path&gt; foo.app/Contents/Frameworks/&lt;lib_name&gt;</code></p></li> <li><p>Find out what libraries each binary links to.</p> <p><code>otool -L &lt;binary_file_name&gt;</code></p></li> <li><p>Change the internal libary paths in your binaries</p> <p><code>install_name_tool -change &lt;original_library_path&gt; @executable_path/../Frameworks/&lt;lib_name&gt; &lt;binary_file_name&gt;</code></p></li> </ol><p>I wrote a perl script that automates these steps for my application, but it's a bit too specific to my particular environment to post here.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>You don't need to take care about manual deployment of third-party libraries. I am uploading a patch to Qt that makes it possible to specify additional library search paths, so that the macdeployqt tool finds the third-party dependencies: https://codereview.qt-project.org/#change,47906</p> <p>After this one there will be another commit that will add support for third party libraries' deployment.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Did you check the .app bundle to see if the libraries are <em>really</em> not there?</p> <p>If that's the case, I'd assume there really is a bug in macdeployqt, or it simply can't find the library you are linking. Personally I've never seen macdeployqt actually copy any needed 3rd-party libraries into the bundle.</p> <p>The interesting part is that <em>macdeployqt</em> never ever works directly with the .pro file. It just does some stuff to the produced application bundle. And after a quick glance into the documentation this Qt 4.7 documentation page obviously proves me right:</p> <blockquote> <p>Note: If you want a 3rd party library to be included in your application bundle, then you must copy the library into the bundle manually, after the bundle is created.</p> </blockquote> <p>I'd assume there is a bug in the 4.6 documentation. For me macdeployqt <em>never</em> placed any library files in my bundle (except for the Qt* ones, of course).</p> <p>I did spend a lot of time with this stuff in my past, and ended up writing a simple little (Python) script that packs everything up into my bundle, changes the library names as needed and puts everything in a .dmg file with automatic naming.</p> <p>Possibly not what you wanted to hear, but it works. ;)</p> <br /><br /><br /><h3>回答4:</h3><br /><p>https://github.com/auriamg/macdylibbundler</p> <blockquote> <p>dylibbundler is a small command-line programs that aims to make bundling .dylibs as easy as possible. It automatically determines which dylibs are needed by your program, copies these libraries inside the app bundle, and fixes both them and the executable to be ready for distribution... all this with a single command on the teminal! It will also work if your program uses plug-ins that have dependencies too.</p> </blockquote> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/2809930/macdeployqt-and-third-party-libraries</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/deployment" hreflang="zh-hans">deployment</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Sun, 29 Dec 2019 06:58:26 +0000 久未见 2991865 at https://www.e-learn.cn Macdeployqt is not working https://www.e-learn.cn/topic/2841550 <span>Macdeployqt is not working</span> <span><span lang="" about="/user/232" typeof="schema:Person" property="schema:name" datatype="">旧巷老猫</span></span> <span>2019-12-24 01:25:52</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I've installed the latest version of Qt (5.1) and when I try to deploy my app on Mac using the macdeployqt tool, the app is still not working on other macs. It's completely working on my Mac and it doesn't not indicate any errors. After researches I found this and I think it's my problem : Qt 5.1 and Mac: Bug making macdeployqt not working properly and https://bugreports.qt-project.org/browse/QTBUG-14699 But the explanation is too technical for me (+ english not my native language), I'm a complete beginner, can you explain what do I have to do to simply make my app work on Mac ? Step by step ? It is perfectly functional on Windows (with the standard dlls).</p> <p>Thank you so much, I think it will help a lot of beginners that are going through the same issue.</p> <br /><h3>回答1:</h3><br /><p>There are 3 tools at your disposal to sort out deployment of Qt for OS X (MacOS).</p> <ol><li><p><code>macdeployqt</code>: This tool gathers all the Qt libraries that your application declares it needs in its project, adds them to the app bundle and updates their paths so that your application knows where to find them.</p></li> <li><p><code>otool</code>: A complex tool for examining the contents of binaries, but in this case, used with the <code>-L</code> argument, will display the paths to all the libraries that your application will reference. These are the paths that it will be looking to find those libraries.</p></li> <li><p><code>install_name_tool</code>: Since <code>macdeployqt</code> only handles Qt libraries that are required by your application, you can use <code>install_name_tool</code> to update paths to any other libraries that your app requires. For example, if you have a separate non-Qt framework that your application relies upon, you need to have a post compilation step to copy the framework into the application bundle and then use <code>install_name_tool</code> to update the paths to the framework.</p></li> </ol><p>If you're having problems, check that the libraries / frameworks have been copied to the correct location in the application bundle and then use <code>otool -L</code> to check the paths. If any are incorrect, use name_install tool to fix them.</p> <p>If you still can't get it to work, please edit your question and add the output from using <code>otool -L</code>.</p> <p>Note, historically, various versions of Qt have suffered bugs with the <code>macdeployqt</code> utility, so if it is not working properly, you may also want to check the qt bug tracker.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/17957127/macdeployqt-is-not-working</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c-0" hreflang="zh-hans">c++</a></div> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Mon, 23 Dec 2019 17:25:52 +0000 旧巷老猫 2841550 at https://www.e-learn.cn How do I make apps smaller with qmake and macdeployqt https://www.e-learn.cn/topic/2708221 <span>How do I make apps smaller with qmake and macdeployqt</span> <span><span lang="" about="/user/37" typeof="schema:Person" property="schema:name" datatype="">£可爱£侵袭症+</span></span> <span>2019-12-21 04:49:19</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>How do I make apps smaller with qmake and macdeployqt?</p> <p>I have set QT = core gui in the projects .pro file and run qmake and macdeployqt on the resulting app. </p> <p>The problem is that the program is bundling QtNetwork, QtScript, QtSvg etc. I've tried setting QT -= network script svg (and then make clean, rm -rf *.app, qmake, make). </p> <p>In total the app is 32 MB.</p> <p>.pro file:</p> <pre><code>TEMPLATE = app TARGET = throw DEPENDPATH += . INCLUDEPATH += . CONFIG += x86_64 release QT = core gui unix { CONFIG += link_pkgconfig PKGCONFIG += glib-2.0 } # Input SOURCES += main.cpp # Headers HEADERS += throw.h RESOURCES += throw.qrc ICON = throw.png mac { QMAKE_INFO_PLIST = Info.plist ICON = throw.icns } </code></pre> <br /><h3>回答1:</h3><br /><p>This is a great article about (re)building Qt statically and dynamically to reduce its size considerably: Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler</p> <p>While this <em>is</em> talking about Qt in the windows context, it does give some good insight into how one would go about compiling for minimal size.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>You could strip the binary afterwards in a post-build step. The Qt libraries themselves are shared by default.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/6562725/how-do-i-make-apps-smaller-with-qmake-and-macdeployqt</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/macos" hreflang="zh-hans">macos</a></div> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/qt4" hreflang="zh-hans">qt4</a></div> <div class="field--item"><a href="/tag/qmake" hreflang="zh-hans">qmake</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Fri, 20 Dec 2019 20:49:19 +0000 £可爱£侵袭症+ 2708221 at https://www.e-learn.cn Qt 5.1 and Mac: Bug making macdeployqt not working properly https://www.e-learn.cn/topic/2581128 <span>Qt 5.1 and Mac: Bug making macdeployqt not working properly</span> <span><span lang="" about="/user/96" typeof="schema:Person" property="schema:name" datatype="">自闭症网瘾萝莉.ら</span></span> <span>2019-12-18 03:59:09</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have a problem since the version <code>5.1rc2</code> of <code>Qt</code> for Mac OS X. (5.1 is also affected, not the 5.1rc1)<br /> When I build my app and do a <code>otool -L</code> on the binary file to see the paths of the shared libraries, I get: (it's just a sample, I removed some of them for clarity) </p> <pre><code>/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.37.0) /Users/chris/**Qt5.1.0//5.1.0**/clang_64/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtQuick.framework/Versions/5/QtQuick (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtQml.framework/Versions/5/QtQml (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.1.0, current version 5.1.0) </code></pre> <p>As you can see there is a double slash in the paths of the Qt libraries. When I use macdeployqt to deploy my app, those paths aren't changed to local frameworks (@executable_path/../Frameworks/...), because of this... I have to do it manually with the install_name_tool, and it's really annoying.</p> <p>What can I do to fix this? (I've tried re-installing Qt, cleaning, runing qmake again and rebuilding without change)</p> <br /><h3>回答1:</h3><br /><p>having the same issue. I applied next workaround: </p> <p>after I build my program, I've changed links inside exe to a right ones</p> <pre><code>install_name_tool -change /Users/username/Qt5.1.0//5.1.0/clang_64/lib/QtQuick.framework/Versions/5/QtQuick /Users/username/Qt5.1.0/5.1.0/clang_64/lib/QtQuick.framework/Versions/5/QtQuick &lt;YourExecutable&gt; </code></pre> <p>After this workaround macdeployqt has changed all links inside exe to a relative ones.</p> <p>But my App became broken. The thing is that I've added all my images and QML files into resources. After I ran macdeployqt - I can not run my app. When I ran this with gdb - I see next error:</p> <pre><code>QQmlApplicationEngine failed to load component qrc:/qml/main.qml:-1 File not found Error: Your root item has to be a Window. </code></pre> <p>So somehow all my resources became unavailable. Does anyone know how to fix that?</p> <p>I also started a discussion on qt forum</p> <p><strong>UPDATE, HOW TO DEPLOY:</strong></p> <ol><li><p>Use this script to get rid of double slashes inside dynamic linking paths.</p> <p>./fixqt.sh ~/Qt5.1.0/5.1.0/clang_64</p></li> <li><p>Build macdeployqt tool from this repository.</p></li> <li><p>Run macdeployqt and specify dir with your qml source: </p> <p>macdeployqt MyApp.app/ -qmldir=../src/qml -dmg</p></li> </ol><p>After those steps I managed to run my application on different OS X system, without QT Installed. I've added all my qml files and images into resources. QtQuick and QtQuick.2 modules copied inside MyApp.app/Content/MacOS/</p> <p>Hope it helps</p> <br /><br /><br /><h3>回答2:</h3><br /><p>I'm posting this as a solution as I just lost (another) day to this process with 5.3 (and I assume it is the same for 5.4).</p> <p><code>macdeployqt</code> now works as intended but the failed piece of documentation here is that you need to specify and <strong><em>absolute path</em></strong> to each qml directory (relative might work but I've had no luck at all).</p> <p>Here's how I solved that for my release process:</p> <p>In the project file I now have</p> <pre><code> mac { CONFIG += x86 CONFIG += c++11 #Disable these for development QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9 #I'm not sure I need this QMAKE_POST_LINK = {path to macdeployqt}/macdeployqt {appname}.app -qmldir=$$PWD/qml/{appname}/ -verbose=3 } </code></pre> <p>This effectively calls: <code>macdeployqt appname.app - /path/to/source/code/appname/qml/appname/ -verbose=3</code></p> <p>When the absolute path is specified it appears to work fine but when I use a relative path I run into several problems. <code>PWD</code> is the source directory and the executables are run from the build directory. The absolute path of the build is <code>OUT_PWD</code>.</p> <p>The beauty of keeping this in the release configuration in the project is that I debug normally (no app package) and the release package correctly builds from creator. Theoretically I can just wrap that into a Jenkins build and be done with this headache once and for all.</p> <p><strong><em>The Short Answer</em></strong></p> <p><code>macdeployqt</code> MUST SCAN your qml files if you're using them otherwise the imports will be broken and you'll see errors like:</p> <pre><code>QQmlApplicationEngine failed to load component qrc:/qml/LightAssistant.qml:5 module "QtQuick.Dialogs" is not installed qrc:/qml/LightAssistant.qml:3 module "QtQuick.Window" is not installed qrc:/qml/LightAssistant.qml:4 module "QtQuick.Controls" is not installed qrc:/qml/LightAssistant.qml:1 module "QtQuick" is not installed qrc:/qml/LightAssistant.qml:2 module "QtQuick.Layouts" is not installed </code></pre> <p>Finally, my directory structure looks like this:</p> <pre><code> Project - qml - appname files1.qml files2.qml ... filesX.qml - js - images </code></pre> <p>These then get packaged into the Resource file which, by definition, are not copied to the build directory and thus macdeployqt can't scan them unless the pathing is perfect. By using this build process I have a step in my build (release) that just deals with it and I don't have to run <code>macdeployqt</code> when I'm debugging. Keep in mind if you use the app_bundle you need to run macdeployqt on each build which will really mess with your debugging workflow.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>This thread:</p> <p>http://www.qtcentre.org/threads/55277-Qt-5-1-and-Mac-Bug-making-macdeployqt-not-working-properly</p> <p>contains this link:</p> <p>https://gist.github.com/lasconic/5965542</p> <p>to this script by lasconic (not my work):</p> <pre><code>BIN_FILE=YOURBINARY for P in `otool -L $BIN_FILE | awk '{print $1}'` do if [[ "$P" == *//* ]] then PSLASH=$(echo $P | sed 's,//,/,g') install_name_tool -change $P $PSLASH $BIN_FILE fi done QTDIR=$1 for F in `find $QTDIR/lib $QTDIR/plugins $QTDIR/qml -perm 755 -type f` do for P in `otool -L $F | awk '{print $1}'` do if [[ "$P" == *//* ]] then PSLASH=$(echo $P | sed 's,//,/,g') install_name_tool -change $P $PSLASH $F fi done done </code></pre> <p>You just need to replace <code>YOURBINARY</code> with e.g. <code>myapp.app/Contents/MacOS/myapp</code></p> <p>And <code>QTDIR=$1</code> with <code>QTDIR=/Users/MyName/Qt5.1.0/5.1.0/clang_64</code></p> <p>Save the file in the same dir as myapp.app</p> <p>And run it with</p> <pre><code>sh thankslasconic.sh </code></pre> <p>then you can run</p> <pre><code>macdeployqt myapp.app </code></pre> <p>and it should work. For me it did. That is why I am posting it here.</p> <br /><br /><br /><h3>回答4:</h3><br /><p>I think its a installer bug. All librarys and tool (compiled/linked by installer?) referenced to .../Qt5.1.0//5.1.0/... (with double slash)</p> <p>I've tried online and offline installer for Mac with the same result.</p> <p>I've reported it as a bug. https://bugreports.qt-project.org/browse/QTBUG-32467</p> <br /><br /><br /><h3>回答5:</h3><br /><p>Just as a follow-up, this bug appears to be fixed in Qt5.1.1 https://bugreports.qt.io/browse/QTBUG-32365</p> <br /><br /><br /><h3>回答6:</h3><br /><p>Take a look at this site http://www.stringcat.com/company_blog/2013/07/04/failed-to-load-platform-cocoa/ See https://subversion.assembla.com/svn/blacktulipconfidence/branches/GuiDemoMac/ at the end of this page.</p> <br /><br /><br /><h3>回答7:</h3><br /><p>Tried all of the above with qt 5.1.1 but always got this crash:</p> <pre><code>QMessageLogger::fatal(char const*, ...) const + 161 QGuiApplicationPrivate::createPlatformIntegration() + 1763 QGuiApplicationPrivate::createEventDispatcher() + 28 QCoreApplication::init() + 101 QCoreApplication::QCoreApplication(QCoreApplicationPrivate&amp;) + 42 </code></pre> <p>so I created this elixir, YMMV:</p> <p>1) get the above mentioned mostly kinda working macqtdeploy from github.</p> <p>2) build this new macqtdeploy</p> <p>3) add this to main.cpp for mac os x only. this stuffs "-platformpluginpath" into argv before starting qapplication.</p> <pre><code>int macStart(int argc, char *argv[]) { QFileInfo fi(argv[0]); QDir plugd(fi.dir()); plugd.cdUp(); plugd.cd("PlugIns"); QString plugins = plugd.absolutePath(); qDebug() &lt;&lt; "PlugIns" &lt;&lt; plugins; char* argv_sub[argc + 2]; for (int i = 0; i &lt; argc; ++i) { char* temp = (char*) malloc(strlen(argv[i]) + 1); strcpy(temp, argv[i]); argv_sub[i] = temp; } char ppp[255]; strcpy(ppp, "-platformpluginpath"); argv_sub[argc] = ppp; char pathx[2048]; strcpy(pathx, (char*) plugd.absolutePath().toLocal8Bit().constData()); argv_sub[argc + 1] = pathx; DCApplication app(argc + 2, argv_sub); app.startup(); return app.exec(); } </code></pre> <p>4) build app</p> <p>5) run new macqtdeploy on app</p> <p>6) goodness</p> <br /><br /><br /><h3>回答8:</h3><br /><p>set plugin folder to libraryPaths</p> <pre><code>QStringList paths; paths.append("folder with plugins"); //can be inside bundle QApplication::setLibraryPaths(paths); </code></pre> <br /><br /><br /><h3>回答9:</h3><br /><p>I always ended up in this discussion when looking for a similar error with macdeployqt and QT Quick 2.0 using QML.</p> <p>The error I found was this:</p> <p><code>Machine:MacOS MyName$ ./tool QQmlApplicationEngine failed to load component qrc:/main.qml:1 plugin cannot be loaded for module "QtQuick": '/Users/thorstenbux/DAQRI/gitHub/artoolkit6/Source/Utilities/ImageDBSerialiser/build-ui/imageDatabase.app/Contents/PlugIns/quick/libqtquick2plugin.dylib' is not a valid Mach-O binary (not a dynamic library)</code></p> <p>and this:</p> <p><code>ERROR: Could not parse otool output: "/Users/myname/DAQRI/gitHub/tool/Source/Utilities/tool/build-tool-Desktop_Qt_5_8_0_clang_64bit-Release/tool.app/Contents/PlugIns/quick/libqtquick2plugin.dylib:\n"</code></p> <p>I created a separate question for that kind of error here: QT Quick (QML) assemble mac-.bundle -&gt; not a dynamic library error when using macdeployqt</p> <p>Just in case someone has the same issue and reads this thread.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/17475788/qt-5-1-and-mac-bug-making-macdeployqt-not-working-properly</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/macos" hreflang="zh-hans">macos</a></div> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Tue, 17 Dec 2019 19:59:09 +0000 自闭症网瘾萝莉.ら 2581128 at https://www.e-learn.cn How do I make apps smaller with qmake and macdeployqt https://www.e-learn.cn/topic/1434991 <span>How do I make apps smaller with qmake and macdeployqt</span> <span><span lang="" about="/user/98" typeof="schema:Person" property="schema:name" datatype="">六眼飞鱼酱①</span></span> <span>2019-12-03 14:26:47</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="alert alert-danger" role="alert"> <p>How do I make apps smaller with qmake and macdeployqt?</p> <p>I have set QT = core gui in the projects .pro file and run qmake and macdeployqt on the resulting app. </p> <p>The problem is that the program is bundling QtNetwork, QtScript, QtSvg etc. I've tried setting QT -= network script svg (and then make clean, rm -rf *.app, qmake, make). </p> <p>In total the app is 32 MB.</p> <p>.pro file:</p> <pre><code>TEMPLATE = app TARGET = throw DEPENDPATH += . INCLUDEPATH += . CONFIG += x86_64 release QT = core gui unix { CONFIG += link_pkgconfig PKGCONFIG += glib-2.0 } # Input SOURCES += main.cpp # Headers HEADERS += throw.h RESOURCES += throw.qrc ICON = throw.png mac { QMAKE_INFO_PLIST = Info.plist ICON = throw.icns } </code></pre> </div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>This is a great article about (re)building Qt statically and dynamically to reduce its size considerably: <a href="http://www.formortals.com/build-qt-static-small-microsoft-intel-gcc-compiler/" rel="nofollow">Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler</a></p> <p>While this <em>is</em> talking about Qt in the windows context, it does give some good insight into how one would go about compiling for minimal size.</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>You could <a href="http://en.wikipedia.org/wiki/Strip_%28Unix%29" rel="nofollow">strip</a> the binary afterwards in a <a href="http://www.qtcentre.org/archive/index.php/t-8730.html" rel="nofollow">post-build step</a>. The Qt libraries themselves are <a href="http://lists.trolltech.com/qt-interest/2006-09/thread00099-0.html" rel="nofollow">shared by default</a>.</p> </div></div><div class="alert alert-warning" role="alert"><p>来源:<code>https://stackoverflow.com/questions/6562725/how-do-i-make-apps-smaller-with-qmake-and-macdeployqt</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/macos" hreflang="zh-hans">macos</a></div> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/qt4" hreflang="zh-hans">qt4</a></div> <div class="field--item"><a href="/tag/qmake" hreflang="zh-hans">qmake</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Tue, 03 Dec 2019 06:26:47 +0000 六眼飞鱼酱① 1434991 at https://www.e-learn.cn Qt 5.1 and Mac: Bug making macdeployqt not working properly https://www.e-learn.cn/topic/585818 <span>Qt 5.1 and Mac: Bug making macdeployqt not working properly</span> <span><span lang="" about="/user/91" typeof="schema:Person" property="schema:name" datatype="">给你一囗甜甜゛</span></span> <span>2019-11-29 03:38:15</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="alert alert-danger" role="alert"> <p>I have a problem since the version <code>5.1rc2</code> of <code>Qt</code> for Mac OS X. (5.1 is also affected, not the 5.1rc1)<br /> When I build my app and do a <code>otool -L</code> on the binary file to see the paths of the shared libraries, I get: (it's just a sample, I removed some of them for clarity) </p> <pre><code>/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.37.0) /Users/chris/**Qt5.1.0//5.1.0**/clang_64/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtQuick.framework/Versions/5/QtQuick (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtQml.framework/Versions/5/QtQml (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.1.0, current version 5.1.0) /Users/chris/Qt5.1.0//5.1.0/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.1.0, current version 5.1.0) </code></pre> <p>As you can see there is a double slash in the paths of the Qt libraries. When I use macdeployqt to deploy my app, those paths aren't changed to local frameworks (@executable_path/../Frameworks/...), because of this... I have to do it manually with the install_name_tool, and it's really annoying.</p> <p>What can I do to fix this? (I've tried re-installing Qt, cleaning, runing qmake again and rebuilding without change)</p> </div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>having the same issue. I applied next workaround: </p> <p>after I build my program, I've changed links inside exe to a right ones</p> <pre><code>install_name_tool -change /Users/username/Qt5.1.0//5.1.0/clang_64/lib/QtQuick.framework/Versions/5/QtQuick /Users/username/Qt5.1.0/5.1.0/clang_64/lib/QtQuick.framework/Versions/5/QtQuick &lt;YourExecutable&gt; </code></pre> <p>After this workaround macdeployqt has changed all links inside exe to a relative ones.</p> <p>But my App became broken. The thing is that I've added all my images and QML files into resources. After I ran macdeployqt - I can not run my app. When I ran this with gdb - I see next error:</p> <pre><code>QQmlApplicationEngine failed to load component qrc:/qml/main.qml:-1 File not found Error: Your root item has to be a Window. </code></pre> <p>So somehow all my resources became unavailable. Does anyone know how to fix that?</p> <p>I also started a discussion on <a href="http://qt-project.org/forums/viewthread/29805/" rel="nofollow">qt forum</a></p> <p><strong>UPDATE, HOW TO DEPLOY:</strong></p> <ol><li><p>Use <a href="https://gist.github.com/lasconic/5965542" rel="nofollow">this script</a> to get rid of double slashes inside dynamic linking paths.</p> <p>./fixqt.sh ~/Qt5.1.0/5.1.0/clang_64</p></li> <li><p>Build macdeployqt tool from this <a href="https://github.com/MaximAlien/macdeployqtfixed" rel="nofollow">repository</a>.</p></li> <li><p>Run macdeployqt and specify dir with your qml source: </p> <p>macdeployqt MyApp.app/ -qmldir=../src/qml -dmg</p></li> </ol><p>After those steps I managed to run my application on different OS X system, without QT Installed. I've added all my qml files and images into resources. QtQuick and QtQuick.2 modules copied inside MyApp.app/Content/MacOS/</p> <p>Hope it helps</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>I'm posting this as a solution as I just lost (another) day to this process with 5.3 (and I assume it is the same for 5.4).</p> <p><code>macdeployqt</code> now works as intended but the failed piece of documentation here is that you need to specify and <strong><em>absolute path</em></strong> to each qml directory (relative might work but I've had no luck at all).</p> <p>Here's how I solved that for my release process:</p> <p>In the project file I now have</p> <pre><code> mac { CONFIG += x86 CONFIG += c++11 #Disable these for development QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9 #I'm not sure I need this QMAKE_POST_LINK = {path to macdeployqt}/macdeployqt {appname}.app -qmldir=$$PWD/qml/{appname}/ -verbose=3 } </code></pre> <p>This effectively calls: <code>macdeployqt appname.app - /path/to/source/code/appname/qml/appname/ -verbose=3</code></p> <p>When the absolute path is specified it appears to work fine but when I use a relative path I run into several problems. <code>PWD</code> is the source directory and the executables are run from the build directory. The absolute path of the build is <code>OUT_PWD</code>.</p> <p>The beauty of keeping this in the release configuration in the project is that I debug normally (no app package) and the release package correctly builds from creator. Theoretically I can just wrap that into a Jenkins build and be done with this headache once and for all.</p> <p><strong><em>The Short Answer</em></strong></p> <p><code>macdeployqt</code> MUST SCAN your qml files if you're using them otherwise the imports will be broken and you'll see errors like:</p> <pre><code>QQmlApplicationEngine failed to load component qrc:/qml/LightAssistant.qml:5 module "QtQuick.Dialogs" is not installed qrc:/qml/LightAssistant.qml:3 module "QtQuick.Window" is not installed qrc:/qml/LightAssistant.qml:4 module "QtQuick.Controls" is not installed qrc:/qml/LightAssistant.qml:1 module "QtQuick" is not installed qrc:/qml/LightAssistant.qml:2 module "QtQuick.Layouts" is not installed </code></pre> <p>Finally, my directory structure looks like this:</p> <pre><code> Project - qml - appname files1.qml files2.qml ... filesX.qml - js - images </code></pre> <p>These then get packaged into the Resource file which, by definition, are not copied to the build directory and thus macdeployqt can't scan them unless the pathing is perfect. By using this build process I have a step in my build (release) that just deals with it and I don't have to run <code>macdeployqt</code> when I'm debugging. Keep in mind if you use the app_bundle you need to run macdeployqt on each build which will really mess with your debugging workflow.</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>This thread:</p> <p><a href="http://www.qtcentre.org/threads/55277-Qt-5-1-and-Mac-Bug-making-macdeployqt-not-working-properly" rel="nofollow">http://www.qtcentre.org/threads/55277-Qt-5-1-and-Mac-Bug-making-macdeployqt-not-working-properly</a></p> <p>contains this link:</p> <p><a href="https://gist.github.com/lasconic/5965542" rel="nofollow">https://gist.github.com/lasconic/5965542</a></p> <p>to this script by lasconic (not my work):</p> <pre><code>BIN_FILE=YOURBINARY for P in `otool -L $BIN_FILE | awk '{print $1}'` do if [[ "$P" == *//* ]] then PSLASH=$(echo $P | sed 's,//,/,g') install_name_tool -change $P $PSLASH $BIN_FILE fi done QTDIR=$1 for F in `find $QTDIR/lib $QTDIR/plugins $QTDIR/qml -perm 755 -type f` do for P in `otool -L $F | awk '{print $1}'` do if [[ "$P" == *//* ]] then PSLASH=$(echo $P | sed 's,//,/,g') install_name_tool -change $P $PSLASH $F fi done done </code></pre> <p>You just need to replace <code>YOURBINARY</code> with e.g. <code>myapp.app/Contents/MacOS/myapp</code></p> <p>And <code>QTDIR=$1</code> with <code>QTDIR=/Users/MyName/Qt5.1.0/5.1.0/clang_64</code></p> <p>Save the file in the same dir as myapp.app</p> <p>And run it with</p> <pre><code>sh thankslasconic.sh </code></pre> <p>then you can run</p> <pre><code>macdeployqt myapp.app </code></pre> <p>and it should work. For me it did. That is why I am posting it here.</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>I think its a installer bug. All librarys and tool (compiled/linked by installer?) referenced to .../Qt5.1.0//5.1.0/... (with double slash)</p> <p>I've tried online and offline installer for Mac with the same result.</p> <p>I've reported it as a bug. <a href="https://bugreports.qt-project.org/browse/QTBUG-32467" rel="nofollow">https://bugreports.qt-project.org/browse/QTBUG-32467</a></p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>Just as a follow-up, this bug appears to be fixed in Qt5.1.1 <a href="https://bugreports.qt.io/browse/QTBUG-32365" rel="nofollow">https://bugreports.qt.io/browse/QTBUG-32365</a></p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>Take a look at this site <a href="http://www.stringcat.com/company_blog/2013/07/04/failed-to-load-platform-cocoa/" rel="nofollow">http://www.stringcat.com/company_blog/2013/07/04/failed-to-load-platform-cocoa/</a> See <a href="https://subversion.assembla.com/svn/blacktulipconfidence/branches/GuiDemoMac/" rel="nofollow">https://subversion.assembla.com/svn/blacktulipconfidence/branches/GuiDemoMac/</a> at the end of this page.</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>Tried all of the above with qt 5.1.1 but always got this crash:</p> <pre><code>QMessageLogger::fatal(char const*, ...) const + 161 QGuiApplicationPrivate::createPlatformIntegration() + 1763 QGuiApplicationPrivate::createEventDispatcher() + 28 QCoreApplication::init() + 101 QCoreApplication::QCoreApplication(QCoreApplicationPrivate&amp;) + 42 </code></pre> <p>so I created this elixir, YMMV:</p> <p>1) get the above mentioned mostly kinda working macqtdeploy from <a href="https://github.com/MaximAlien/macdeployqt" rel="nofollow">github</a>.</p> <p>2) build this new macqtdeploy</p> <p>3) add this to main.cpp for mac os x only. this stuffs "-platformpluginpath" into argv before starting qapplication.</p> <pre><code>int macStart(int argc, char *argv[]) { QFileInfo fi(argv[0]); QDir plugd(fi.dir()); plugd.cdUp(); plugd.cd("PlugIns"); QString plugins = plugd.absolutePath(); qDebug() &lt;&lt; "PlugIns" &lt;&lt; plugins; char* argv_sub[argc + 2]; for (int i = 0; i &lt; argc; ++i) { char* temp = (char*) malloc(strlen(argv[i]) + 1); strcpy(temp, argv[i]); argv_sub[i] = temp; } char ppp[255]; strcpy(ppp, "-platformpluginpath"); argv_sub[argc] = ppp; char pathx[2048]; strcpy(pathx, (char*) plugd.absolutePath().toLocal8Bit().constData()); argv_sub[argc + 1] = pathx; DCApplication app(argc + 2, argv_sub); app.startup(); return app.exec(); } </code></pre> <p>4) build app</p> <p>5) run new macqtdeploy on app</p> <p>6) goodness</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>set plugin folder to libraryPaths</p> <pre><code>QStringList paths; paths.append("folder with plugins"); //can be inside bundle QApplication::setLibraryPaths(paths); </code></pre> </div></div><div class="panel panel-info"><div class="panel-heading">Thor_Bux</div><div class="panel-body"> <p>I always ended up in this discussion when looking for a similar error with macdeployqt and QT Quick 2.0 using QML.</p> <p>The error I found was this:</p> <p><code>Machine:MacOS MyName$ ./tool QQmlApplicationEngine failed to load component qrc:/main.qml:1 plugin cannot be loaded for module "QtQuick": '/Users/thorstenbux/DAQRI/gitHub/artoolkit6/Source/Utilities/ImageDBSerialiser/build-ui/imageDatabase.app/Contents/PlugIns/quick/libqtquick2plugin.dylib' is not a valid Mach-O binary (not a dynamic library)</code></p> <p>and this:</p> <p><code>ERROR: Could not parse otool output: "/Users/myname/DAQRI/gitHub/tool/Source/Utilities/tool/build-tool-Desktop_Qt_5_8_0_clang_64bit-Release/tool.app/Contents/PlugIns/quick/libqtquick2plugin.dylib:\n"</code></p> <p>I created a separate question for that kind of error here: <a href="https://stackoverflow.com/questions/42522830/qt-quick-qml-assemble-mac-bundle-not-a-dynamic-library-error-when-using-ma" rel="nofollow">QT Quick (QML) assemble mac-.bundle -&gt; not a dynamic library error when using macdeployqt</a></p> <p>Just in case someone has the same issue and reads this thread.</p> </div></div><div class="alert alert-warning" role="alert"><p>来源:<code>https://stackoverflow.com/questions/17475788/qt-5-1-and-mac-bug-making-macdeployqt-not-working-properly</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/macos" hreflang="zh-hans">macos</a></div> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/macdeployqt" hreflang="zh-hans">macdeployqt</a></div> </div> </div> Thu, 28 Nov 2019 19:38:15 +0000 给你一囗甜甜゛ 585818 at https://www.e-learn.cn