Custom QWidgets. How do I build/get the pyqt5 plugin for Qt Designer on Mac? - macos

I want to be able to create my own custom widgets in Qt Designer using the pyqt5 plugin on my Mac!
On my windows system this is easy. I have/install pyqt5-tools, this contains pyqt5.dll and I copy this into the Qt Designers plugin directory (these packages were all installed via winPython).
I set PYQTDESIGNERPATH=.
In my current directory I have ledplugin.py and ledwidget.py
I start Qt Designer and I have my custom widget to drag and drop
( this tutorial was taken from https://www.ics.com/blog/integrating-python-based-custom-widget-qt-designer )
On my Mac, I can't figure out what the equivalent .dylib of pyqt5.dll is? What is it? Where do I get it? How do I build it?
I try: brew install Qt Creator, that doesn't have the pyqt plugin. I try: brew install pyqt5, that creates: libpyqt5qmlplugin.dylib. I copy that into the Qt Designer plugin dir and the plugin loads, but it doesn't seem to do anything with my .py plugin/widget files.
How do I get this working on a Mac? What is the actual .dylib plugin I'm looking for? I can't find anything googling around.
Thanks for any help

As my comment explained: the Qt designer plugin can be built via the reference link (SIP/PyQt5 via RiverBank and Qt src via Qt).
Make sure your Qt versions match, although Qt docs do say plugins of lower versions should work with Designers on higher versions, but I'm sure there's a limit.
Build inside a python venv, as suggested.
You'll need xtool dev pkg for building.
Everything built really easy for me.
This will place your pyqt5.dylib plugin right in your Qt/clang_64/plugins/designer folder (it will also build it in pyqt5 make folder)
At this point I expected things to work. The plugin shows that it loads fine inside Designer.
Some extra notes:
running from command line can help with debugging: Qt/clang_64/bin/Designer.app > show package > /MacOS/Designer (drag this to a terminal to execute from command line)
set an env variable (>>export QT_DEBUG_PLUGINS=1) will give debug info and show lots of stuff including that pyqt5.dylib loads fine
widget plugins are two files: widget.py and the widgetplugin.py file that exposes the widget to designer. This plugin file MUST end with "plugin.py"
widgetplugin.py files can reside in a number of places:
in /[Designer App]/plugins/designer/python/
in ~/user dir/.designer/plugins/python/
in a directory of you choosing using env var PYQTDESIGNERPATH
However, at this point still nothing showed in Designer and I had no errors to go by. Since I just built pyqt5.dylib, I figured I'd simply put a bunch of print statements in it, re-make it and debug to figure out why the pyqt5 plugin loaded fine, but my custom widgets were nowhere to be found...
first issue was trouble loading a python environment:
for this issue, I simply copied my (I use brew) /usr/local/Cellar/python/3.7.2/Frameworks/Python.framework to Qt/clang_64/lib (I'm sure there's a proper PATH/PYTHONPATH you can set for this, I'll figure that out later)
after that came, missing PyQt5.sip module
for this, I installed (pip install) pyqt5-sip and then put in in my PYTHONPATH
After that, everything finally worked and I could see my custom plugins inside Qt Designer.

Related

Qt deploy not working on windows normally

I am using Visual Studio + Qt addon with Qt 5.15.2 x64 and set Run deployment tool to Yes. It seems like this deployment tool is poorly designed and broken. Never understand why Qt cannot make own runtime distibution for Windows like Microsoft did. After deployment when I am trying to open my release exe it just not open. Nothing happens. Yes, I can put it into qt bin folder that weights few gigabytes and it works, but it looks like deploy tool missed some libraries. How to deploy on windows without problems?
(Do not advice me to copy entire Qt bin and remove files one by one and find minimal combination of libraries, I want to make qt deploy automatically)
My errors on app launch:
qrc:/qml/main.qml:3:1: module "QtGraphicalEffects" is not installed
qrc:/qml/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/qml/main.qml:1:1: module "QtQuick" is not installed
qrc:/qml/main.qml:3:1: module "QtGraphicalEffects" is not installed
qrc:/qml/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/qml/main.qml:1:1: module "QtQuick" is not installed
qrc:/qml/main.qml:3:1: module "QtGraphicalEffects" is not installed
qrc:/qml/main.qml:2:1: module "QtQuick.Window" is not installed
qrc:/qml/main.qml:1:1: module "QtQuick" is not installed
I found 3rd party Qt deploy toolkit for Windows. It just works fine out of box. I think the only way to solve problems with windeployqt is do not use it and switch to something else.
https://github.com/QuasarApp/CQtDeployer
I usually run windeployqt manually, if it help you:
path\to\windeployqt.exe --release --compiler-runtime path\to\release\build
for example
C:\Qt\5.15.2\msvc2019_64\bin\windeployqt.exe --release --compiler-runtime .\release
Update: if you use QML frontend in your app, as you described in question update, then also specify --qmldir argiment, so that windeployqt could find dependencies not only in compiled .exe import table, but also in non-compiled QML text files. See approved solution https://stackoverflow.com/a/39717117/12691808.

How to build firefox as installer

Now I'm trying to build firefox according to https://developer.mozilla.org/en-US/docs/Simple_Firefox_build
So I can get firefox from mozilla-release\obj-i686-pc-mingw32\dist\bin folder.
I want to get setup.exe from this result.
How can I build firefox as installer type.
./mach build installer is both the official way to build a Firefox installer, and the way that worked for me.
Note: it will put the installer in mozilla-release\obj-i686-pc-mingw32\dist\install\sea\firefox-36.0a1.en-US.win32.installer.exe (where “36.0a1” is replaced whatever version you're compiling.
Note 2: You may need to add the line mk_add_options WIN32_REDIST_DIR="$VCINSTALLDIR\redist\x86\Microsoft.VC80.CRT" (or similar) to your .mozconfig to build a version that installs on non-developer’s computers. This part didn’t actually work for me. :(

Macdeployqt doesn't include Phonon in the .app bundle

Hello fellow programmers!
I have written a video player using Qt. Everything works fine on my Mac, but when I use macdeployqt to deploy my application and I open the result, I am getting the following message:
WARNING: bool Phonon::FactoryPrivate::createBackend() phonon backend plugin could not be loaded
WARNING: Phonon::createPath: Cannot connect Phonon::MediaObject ( no objectName ) to Phonon::AudioOutput ( no objectName ).
WARNING: bool Phonon::FactoryPrivate::createBackend() phonon backend plugin could not be loaded
...
And of course it doesn't play audio (in my machine or in another). Maqcdeployqt does include the other parts of Qt and the 3 party libs wo problems. Its just the damm Phonon.
I feel that i'm making a dumb mistake but i just cant find it.
The otool log of my app shows:
#executable_path/../Frameworks/phonon.framework/Versions/4/phonon (compatibility version 4.4.0, current version 4.4.0)
As the only reference of phonon.
I read in the documentation of qt the following:
"The Mac deployment tool can be found in QTDIR/bin/macdeployqt. It is designed to automate the process of creating a deployable application bundle that contains the Qt libraries as private frameworks.
The mac deployment tool also deploys the Qt plugins, according to the following rules:
-Debug versions of the plugins are not deployed.
-The designer plugins are not deployed.
-The Image format plugins are always deployed.
-SQL driver plugins are deployed if the application uses the QtSql module.
-Script plugins are deployed if the application uses the QtScript module.
-The svg icon plugin is deployed if the application uses the QtSvg module.
-The accessibility plugin is always deployed. "
Maybe i have a debug version of phonon? I don't know, i have tried to deploy the debug and the release versions and none have worked.
Also i founded a related problem in this page:
http://www.justinfx.com/tag/phonon/
So i included a folder named 'PlugIns' in my bundle with the phonon_backened folder from my system inside of it after the deploy: it played audio on my machine (but it didn't play it on another) and my app crashed at the end so that cant be the way.
I'm using c++, Qt 4.8.5, the phonon from the SDK (i didn't install any version of phonon, i just installed Qt), and Mac OS X (10.6.8)
I would love to hear any idea or suggestion.
Thanks in advance.
I didn't find the source of the error, but I bypassed it by macdeploying the phonon example from the qt examples folder on another Mac (i.e. Lion). It included the folder 'Plugins' inside the bundle with all the phonon stuff, so I include now that folder into the bundles macdeployed in my Snow Leopard manually. It is ugly but it works from now.
If anyone knows the way to really fix the issue I will be happy to hear it.
I used py2app (neither pyinstaller nor cx_freeze worked) and it created the app distribution folder almost perfectly, except it did not copy the phonon backends. Running macdeplpyqt did not help.
The location of your plugins in your app structure is MyApp.app/Contents/PlugIns so I copied over the folder from Qt install (/Developer/Applications/Qt/plugins/phonon_backend/ ) into the PlugIns folder. That still gave the same error.
Digging in further I saw that MyApp.app/Contents/Resource/qt.conf file is expecting the plugins to be in the Resource/qt_plugins folder so I made a symbolic link from from PlugIns MyApp.app/Contents/PlugIns to MyApp.app/Contents/Resource/qt_plugins and everything works now.

ubuntu 13.04, can't see source files of c++ project in QT creator

On ubuntu 12.10 I've been using Qt Creator for a while. After updating to ubuntu 13.04 I've encountered the problem, that I can no longer see my src-files in the project editor. I only see the .pro and .pri file.
I've checked that the build path is correct and re-installed QT 5. As well, I can compile and run the project as usual, but the src-files just won't appear in the editor. I used to run the project with QT4 (qmake-qt4 makefile.pro), might this interfere?
I found a workaround by adding the required source and header files manually via right-click on the project. But this is rather inconvenient as the source files are spread across several folders. I still couldn't figure out why QT creator does not add them automatically after I've upgraded to ubuntu 13.04 and QT 5 (downgrade to QT 2.7 was in vain, too).

setting up qt for xcode debugging

I just installed QT 4.6 on snow leopard 10.6.3. I wrote a really simple program. I can generate a xcode project using qmake, but I can't step into QT function. How can I set it up?
By default, qt is built with a debug and a non-debug library. This is my understanding. For example,
% ls /Library/Frameworks/QtCore.framework/
Contents/ Headers# QtCore# QtCore.prl QtCore_debug# QtCore_debug.dSYM/ QtCore_debug.prl Versions/
Also, my default from source build of Qt 4.7 branch also has the *_debug libs.
Setting up for Xcode is cake, you just set up your project and
% qmake -spec macx-xcode
This -spec is the default for the official mac distribution, but if you build your own from source the default is macx-g++ which creates a Makefile project.
This generates a MyProject.xcodeproj that comes preconfigured to link all the necessary Qt frameworks, sets up paths, and has a Release and Debug build target set to the same options as the official SDK's.
This is all assuming you have your qt project file set up, if you need to generate that first from a raw source directory:
% qmake -project
Debugging works "out of the box" for these generated *.xcodeproj files. However, there's one little "hitch". Since Qt is full of custom data types, Xcode doesn't know how to display their "values" in the debugger's summary pane. So you can't see what value a QString has, for example.
There's a method of entering custom macros for display, but I've found these often (always?) don't work for QObjects.
To get that working, I've started a project that uses xcode's debugger c callbacks (also mentioned in the above linked article, though their example doesn't even work o.O). I call it Qt4DataFormatters.
I've just started it and have been adding types as the need arises. It's dirt simple to create one using the existing functions as a template though.
I haven't tried this on Mac, but on Linux you need to take the following process:
First, you need to setup Qt so that it has debugging symbols available to you:
./configure -debug-and-release separate-debug-info # other options
With the debugging symbols available, you should now be able to get valid stack traces.
When building your application with qmake, you need to have the debug (or debug_and_release) flag set in your project file:
CONFIG += debug
Once you've done that, you should only need to tell the debugger where the Qt source is located:
(gdb) dir /path/to/qt/src
After that, list should show you the actual Qt source code. You may need to add additional directories under the src directory for the debugger to pick it all up.

Resources