Qt How to make and install plugins? - qt

I would like to use the Qt Quick Components for Desktop mentioned here: http://labs.qt.nokia.com/2011/03/10/qml-components-for-desktop/
The author gives the following installation-instructions:
Since all of this is developed as a plugin to Qt itself, all you need to get started is the Qt 4.7.2 SDK. Just check out the http://qt.gitorious.org/qt-components/desktop and do the equivalent of a qmake && make install on your system.
I cloned the repository, executed qmake, mingw32-make and mingw32-make install on it in the command-line.
A new folder was created which includes the files libstyleplugin.a and styleplugin.dll.
I just don't know what to do with them. The sample-qml-files (using the components I try to install here) show nothing in the QML-Viewer, which means they aren't isntalled correctly.
So what am I supposed to do? (btw. I'm on Windows).

Hedge, I've done that on Linux but I believe you will be able to do the same on Windows. You already built the plugin which is good. Cause it seems "make install" doesn't really work (lets not blame the trolls - its just an experimental project), you need to do that manually. Now you need to do the following:
Create "imports" directory inside the directory whether you installed Qt.
Create "Qt/labs" directory inside that "imports" directory so overall it looks like this: YOUR_QT_DIR/imports/Qt/labs.
Copy "components" directory from the director where you built the components to "YOUR_QT_DIR/imports/Qt/labs" so it looks like this: YOUR_QT_DIR/imports/Qt/labs/components.
Go to "examples" directory in the directory where you built the components. You will find Browser.qml, Gallery.qml and Panel.qml files there. Open say Gallery.qml in a text editor and replace the following two lines on the top:
import "../components"
import "../components/plugin"
with
import Qt.labs.components 1.0
save changes and run Gallery.qml in qmlviewer. You should be able to run it.
Also you could leave the import statements from Gallery.qml as they were but that would rely on the relative directory where you built the components and won't work anywhere else.
Hope that helps

On Windows my directory ended up being C:\QtSDK\Desktop\Qt\4.7.3\mingw.
Hope this helps!

Related

QML module not found when using KDE Kirigami

So I decided to use KDE Kirigami UI framework in my app so I followed the instructions here. I cloned the repo in my app directory and then added it with a simple include(kirigami/kirigami.pri) in my project file.
Now this works, however the problem I encountered is that in QML there is always the error: QML module not found when I import the plugin (import org.kde.kirigami 2.9). The project still compiles and runs just fine and I am able to use the UI components I need, however the major issue is that code completion and syntax highlighting for the Kirigami plugin do not work.
A similar question has been asked before here, I have tried all the suggestions in the answers of that thread but none of them worked:
I imported QQmlEngine::addImportPath the kirigami/src/controls folders using absolute and relative paths. I also tried with qrc:/.
I added a QML_IMPORT_PATH += $$PWD/kirigami/src/controls $$PWD/kirigami line to my project file.
When you mouse over the "module org.kde.kirigami not found" error marker in a QML file, the popup tells you that Qt Creator is looking in QML_IMPORT_PATH for these files. It also tells you how to set this.
By adding QML_IMPORT_PATH += … to your project file, you have set it for a qmake based build process. However, Kirigami projects usually use CMake, and that might be the reason why your previous attempts did not work out.
To set QML_IMPORT_PATH for a CMake based build system, you would open the CMakeLists.txt file from the root of your project tree and add the following section on top:
# ------------------------- BEGIN: lists to maintain manually -------------------------
# Directories where Qt Creator can find QML files of Kirigami etc. on your system.
# (This setting is cached in variable QML_IMPORT_DIR, see below. Delete
# ${BUIL_DIR}/CMakeCache.txt to make make changes here effective.)
list(APPEND QML_DIRS "/usr/lib/x86_64-linux-gnu/qt5/qml")
# ------------------------- END: lists to maintain manually -------------------------
# Tell Qt Creator where to find QML files.
# (The build process will work without this, but no code completion etc..)
set(
QML_IMPORT_PATH "${QML_DIRS}"
CACHE STRING "Qt Creator 4.1 extra qml import paths"
)
Of course, adapt it to the correct directory for your system. On a Debian / Ubuntu based system, the following will determine the directory containing Kirigami QML files installed from the repositories:
dpkg -L qml-module-org-kde-kirigami2 | grep "\.qml"
Source: another answer on StackOverflow

Link dynamically against Public\Qt inside ocean

Using Petrel 2016.1
Libraries reference:
https://www.ocean.slb.com/~/media/files/testing%20plug%20ins/libraries/petrel_2016-1_3rd_party_libraries.html
My plugin uses Qt for a window and some plots with qwt. I would like to link against the Qt dlls present at Petrel\Public\Qt to save some space while deploying the app and because is not possible to deploy libs already present in Petrel as public libs by policy.
I've successfully linked with the same Qt version over there. The problem is that PluginPackager.exe does not see the libs. I've tried editing PluginPackager.exe.config inside Petrel dir to include Public\Qt, copied it to the Release folder, copied it to the main project folder and every dir that I may suspect PluginPackager.exe is looking for this file but nothing seems to cause any effect.
I've copied the Qt dlls to the Release folder, so PluginPackager.exe could see them and register the Plugin. It works, even if I delete the Qt dlls from the Release folder afterwards. Petrel is loading them from Public\Qt. The problem is that when I try to open the Qt window, a message saying that Qt failed to load plugin windows.
I figured that it is related to qwindows.dll, which is inside Public\Qt\plugins\platforms. If I set the environment variable QT_QPA_PLATFORM_PLUGIN_PATH to C:..\petrel...\Public\Qt\plugins\platforms, it works fine. I've tried to use addLibraryPath() from QApplication with no success.
I guess we have everything we need inside Public\Qt, but for some reason Petrel is not finding it. Two questions, then:
1- How to make PluginPackager to see all the libs inside Public\Qt?
2- How to make my application to find qwindows.dll?
Plugin has code in C#, C++ cli and C++
EDIT 1:
Ok, for Q.2 I've found a solution by trial and error.
QString path = QDir::currentPath();
QString finalPath = QDir(path).filePath("Public/Qt/plugins");
QApplication::addLibraryPath(finalPath);
This will add the plugins dir to the qt lib search path and does the trick. I hope I can deploy using this.
EDIT 2:
For Q.1
I realize now that the PluginPackager only sees things inside the Extensions folder. The problem was that, in my opinion, the folder name Public is misleading. This led me to think that all libs inside that folder could be used by developers freely. The Ocean guide states that all libs other than the ones inside Extensions are considered internal libs:
The PluginPackager.exe assumes that files in the Petrel installation directory tree other than those in the Extensions folder are internal Petrel libraries.
Well, why name a folder Public if all the libs inside it are internal? This is really confusing. Besides, the Slb.Ocean libs inside the Public folders are Ok to use, the others are not? As PluginPackager.exe.config has Public\ but not the folders inside it.

How to use the QtVirtualKeyboard

I try to integrate the QtVirtualKeyboard into a prototype, but I fail.
It is the first time I work with multiple projects or where I have to include non-basic-stuff in QML/QMake-Project.
I got the code from the git-repository and were successfully running the examples. But now I am puzzled on how to integrate it into my own project.
My project structure is as follows
Proto (dir)
+- Proto.pro
+- main.cpp
+- ...
+---QML (dir) <--- QML-Files
| +-main.qml
| +---CustomControls (dir)
| +---...
+---CPP (dir) <--- C++-Files and Headers
+---RES <--- Icons and stuff
Now I thought I might just add the src-project from the virtual keyboard to the root-folder (Proto), and add something like:
SUBDIR += src/src.pro
to the Proto.pro-file
=> Yes, I can do that, but there is no merrit in it.
So what do I need to do, to actually use it? It must be really easy, for I can't find any question regarding it anywhere on google, youtube or SO.
EDIT => I still fail. This is my story:
I tried the deployment-method, followed the instructions here.
As I'd prefer to have the keyboard within the application, I did the following:
I added the make install-stept
I passed qmake an additional argument "CONFIG+=disable-desktop
It seemed to work. Got new files in the mentioned directories:
C:\Qt\Qt5.7.0\5.7\mingw53_32\qml\QtQuick\VirtualKeyboard
C:\Qt\Qt5.7.0\5.7\mingw53_32\qml\QtQuick\Virtualkeyboard\Styles
C:\Qt\Qt5.7.0\5.7\mingw53_32\plugins\platforminputcontexts\
Now in my project, I added the line
QT_IM_MODULE=qtvirtualkeyboard myapp
And tried to import it in my main.qml
import QtQuick.VirtualKeyboard 2.0 // (also tried it with 2.1)
I got the error:
[path]/main.qml:10 module "QtQuick.VirtualKeyboard" is not installed
And that concludes my story sofar. Any suggestions where I failed?
Ok, I finally succeeded. Though it is indeed very close to the documentation I don't think the documentation is easily understood. Therefor I will post this step-by-step-guid, where I will clear my own misconceptions.
Download the sourcecode from the git-repository
Open the project qtvirtualkeyboard.pro with the QtCreator, and run it with the configuration release
It will create some directories and files in your Qt-installation dir. You do not need to add anything in your project directory. Once done and your good for all projects to come.
Make sure, you set the QT_IM_MODULE environment variable to include qtvirtualkeyboard. My mistake was, to assume (I don't know why) this might be done in the projects .pro-file. This seems to be wrong. The C++-method seems safe:
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
If you want to have the keyboard within your application, add
CONFIG += disable-desktop to your projects .pro-file
Have fun!
If you select the Qt Virtual Keyboard component under a particular Qt version, you should get the prebuilt binaries:
The Qt Enterprise Add-ons component has a virtual keyboard sub-component (?) which might only give you the sources.. not sure.
If you really need to have the module in your project's Git repo, it might be easier to just add it as a submodule, and reference that in a "3rdparty" SUBDIRS sub-project.

moving Qt directory

I'm working on a Qt4.7.3 project on mac osX (with xCode). I would like to move my Qt directory (installed with Qt installer). The problem is that some Qt executable files have hardcoded paths. I've already recompiled Qmake specifying the new Qt directory. So the project now compile and link perfectly, but at run time it cannot find the qt libraries (it still look into my old Qt directory). Is there other harcoded path somewhere, other configuration files to edit?
By the way, the reason why I want to move my Qt directory is to allow to share qt files via revision control tool.
The pre-built installer actually puts all the framework files into the system location (/Library/Framworks/) and you will have a hard time moving those.
Your best bet is to build it from source and specify a different install location. ./configure -help will show you how. (Use the -prefix option)
Hard links could be a way to go in this kind of situation I guess.
Try this.
Create qt.conf file in the same folder as your qmake.exe file.
[Paths]
Prefix = E:/Qt/4.8.3
Follow this link for detail description.
http://richardt.name/blog/moving-a-qt-installation-directory/

Enabling JPEG support for QImage in py2exe-compiled Python scripts?

I'm trying to use a JPEG image in a QImage object from a Python script, with PyQt4.
The script itself works perfectly, the image loads and can be manipulated and rendered and all. However, when I try to "compile" this script with py2exe, everything works but the JPEG image. Replacing it with a PNG equivalent works, but since my program downloads images from the web, they won't always be in PNG format and I can't afford converting them all with another library.
I've discovered that JPEG image support for QImage, along with other image formats, is provided by some DLLs in the \qt\plugins\imageformats directory (they're called qjpeg4.dll and qjpeg4d.dll). I think I need to use them somehow in my executable, but I don't know how. I've tried simply copying them to my exe directory, no luck. I've tried, as indicated here, to include those files as data_files in the setup.py script, but no luck (it looks like all it does is copying these files to the exe's directory, so it changes nothing from copying them manually anyway).
I'm sure there's a handful of applications out there using PyQt with JPEG images, how do they do it? It seemed like a trivial task but I'm stuck on it now.
Also, I want my app to be cross-platform (why else would I be coding in Python?), I hope I won't run into such packaging trouble (it's not the only one) when packaging for OS X or Linux. Will I?
After hours of stumbling around with the same issue, I’d like to share the solution that worked for me on windows vista:
using python2.6
copy the following directory into your dist directory generated by py2exe:
C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats
I just dropped the imageformats directory directly into my dist directory, without any further modifications to qt.conf or anything like that. I haven’t tried it, but this may work for phonon as well.
I'll have to confess I never managed to get the py2exe + pyqt combination quite right (and, py2exe doesn't help at all with cross-platform packaging). PyInstaller seems to be much better -- the docs at http://www.pyinstaller.org/ are old, but the svn trunk is much more recent. Some docs are in slides given at the recent Pycon Italia Tre conference -- http://www.pycon.it/static/stuff/slides/distribuire-programmi-python-con-pyinstaller.pdf -- and, the slides are in English, and contain the current maintainer's email, so they should help! (And, let's all lobby the current maintainer to update the docs...!-)
Try adding a qt.conf file to your exe's directory, to tell qt where to find binaries and plugins.
Something like the following works for the simple case, where you just dump all dll's in the same dir as the exe:
[Paths]
Prefix = .
Plugins = .
Update: Then copy your plugins-contents (the imageformat/sqldriver directories etc) to the exe dir. I don't think you can load plugin dlls from the same directory as the exe. See Qt plugin doc for details on plugon subdirectories. (Or, leave out the 'plugins = .' and copy the plugins dir to the exe dir, so you have /plugins/imageloaders/qjpeg4.dll).
Etienne -- Thank you for the tip. After much reading and trial-and-error, I arrived at the same conclusion: use PIL to show jpegs in a py2app-generated app.
http://www.thetoryparty.com/wp/2009/08/27/pyqt-and-py2app-seriously-i-dont-know-what-to-do-with-you-when-youre-like-this/
What I guess is that the proposed solutions for py2exe/Windows don't necessarily apply to py2app/OSX.
I'm on OSX Leopard.
Let's suppose you have an application MyApp.app.
Put the libraries libqjpeg.dylib and libqgif.dylib in
MyApp.app/Contents/plugins/imageformats/
Put this in qt.conf in MyApp.app/Contents/resources/:
[Paths]
Prefix = .
Binaries = .
On my machine (Leopard) this works.
After trying all the above solutions in vain, I just ended up using PIL to load my images. Since I wanted to convert these images to a texture in an OpenGL Qt widget, the result was the same whether I load the image using Qt or PIL. Still, I'm baffled that such a basic thing as loading JPEGs is so complicated in a GUI library as well-known and widely used as Qt.
I had the exact same problem. Fixed it using this : http://mail.python.org/pipermail/python-list/2008-June/669374.html
Copy Qt plugins to the directory: $YOUR_DIST_PATH/PyQt4/plugins;
Copy qt.conf to your dist directory;
Edit qt.conf, change Prefix to ./PyQt4
For me, the problem was solved just copying the "qt.conf" for the directory of the executable.
You can find the "qt.conf" in ...\PythonXX\Lib\site-packages\PyQt4\qt.conf.
Thanks for help.
Everything above failed for me until I realized that I was bundling the .exe (that is, I had the option "bundle_files" : 2 in my setup.py. I changed it to bundle_files = 2, and now it works great.
The above solutions are fine. Specifically, I just added the following line in my setup.py:
data = [ ("imageformats", glob.glob("C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats*.dll")) ]
(in addition to other files, of course).
Then, the image loading dlls are in MY_EXE_DIR/imageformats
I didn't need a qt.conf to make this work, though I'm sure you could use it if you want to keep your directory tree less cluttered.
It is possible to use the JPEG plugin with a py2exe'd script, even using bundle_files. You need to arrange two things to get this to work properly:
Copy PyQt4/plugins/imageformats to the output directory of py2exe (default: dist)
You only have to copy the formats you actually need.
When use the bundle_files option you need to execlude the Qt dll files from the
zipfile using the --dll-excludes option for pyexe.
You still have to copy the Qt DLLs to the output directory some other way (such as
by using the data_files option).
on windows, suggested solutions work perfectly.
however, on osx can't make it work even with instructions here above.
question is: the libqjpeg.dylib and libqgif.dylib files are located in the /Developer/Applications/Qt/plugins/imageformats/ directory, and that if you have installed Qt itself, not just PyQt. these files do not work for me.
in PyQt distribution, i see the files libqjpeg.bundle and libqgif.bundle in /opt/local/libexec/qt4-mac/plugins/imageformats/, however these are not libraries, and btw i cannot open their contents either, even if they have the .bundle extension. using these files instead does not work either.
i am curious to know what have you done to make it work on osx. i have installed PyQt following this guide.
Thanks for your helpful answers for the question! I have encountered same problem as you did and no solutions could help. Hopefully, I was using VCS and found that old version of my app loaded JPEG images correctly and new versions stopped doing it. I caught this bug using PySide v1.2.2.
To enable libraries loading, I used the same solution as #Macke did (i.e. added and edited qt.conf).
My qt.conf was next:
[Paths]
Binaries = .
Plugins = qtplugins
C:\Python27\Lib\site-packages\PySide\plugins directory was copied to qtplugins directory, so I had next directories:
qtplugins\accessible
qtplugins\codecs
qtplugins\graphicssystems
qtplugins\iconengines
qtplugins\imageformats
I had next code:
class NotesCalendar(QtGui.QCalendarWidget):
note_icon = QtGui.QImage("res/16note.png")
Moving class variable NotesCalendar.note_icon to constructor solved the problem and Qt started loading its libraries correctly. Seems that class variable constructor interrupted some internal PySide stuff.
It works with no problems on Windows. Specifying correct qt.conf and copying plugins directory is enough to enable JPEG support in py2exe + PySide build. Of course, you must have no problems in your own code.
I hope this will save someone a day! ;)

Resources