How to use the QtVirtualKeyboard - qt

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.

Related

Custom plugin for qt is not loaded. How to debug?

I wrote a custom plugin for QCanBus, that simply is a copy of the socketcan plugin but has been renamed and the identifiers have been adjusted to that new name.
I did that copying to first get the plugin recognised before I alter it.
I changed the qmake project to look that way:
TEMPLATE = lib
TARGET = qtcopysocketcanbus
CONFIG += plugin
QT = core serialbus
HEADERS += \
copysocketcanbackend.h
SOURCES += \
main.cpp \
copysocketcanbackend.cpp
DISTFILES = plugin.json
and added the plugin.json like so:
{
"Key": "copysocketcan"
}
I then renamed everything else from socketcan to copysocketcan in the main.cpp, the copysocketcan.cpp and the copysocketcan.h as well.
When I build the project, I get my *.so file which i put into $QT_PLUGIN_PATH/canbus/ on my target.
However, a quick start reveals, that qt only lists the plugins that came with the installation, not my added custom one.
I tried putting QLoggingCategory::setFilterRules(QStringLiteral("qt.canbus* = true")); as first line in my code and hoped getting more debug output, but I only get the debug output that my own application is producing. No output from the actual QCanBus.
So my questions are
How to enable the debug output for qt.canbus? Do I have to build QT with debug config for that?
Does my approach for creating a plugin reasonable?
Any ideas, why the custom plugin is not listed?
Through a helpful comment, I was able to debug the problems. The commentor suggested to use QT_DEBUG_PLUGINS to debug the plugin call. That lead to the appearance of an error message, that clearly stated, that the plugin I was trying to load because it was not a plugin and plugin metadata could not be extracted.
A bit of googling after those messages helped.
The answer to question 1 is:
Yes, you apparently have QT to build with debug information, to get the actual log output.
In my case, I configured the framework with --force-debug-info
For the second question, my approach was indeed reasonable, because as answer for question 3 turned out that one has to include the moc file as soon, as a Q_OBJECT macro is used within a *.cpp file and not in a separate header, which is the case for the canbus plugins. You can read more about that here

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.

Qt5 QML module is not installed

I'm confused about modules in Qt QML. I've read all the docs, but it doesn't make clear some basic ideas.
I understand that i can put a bunch of QML files into a directory and add a qmldir file to describe an identified module. When i do this and adjust the QML_IMPORT_PATH, QtCreator is happy and stops underlining the import ModuleName 1.0 line.
So creator is happy, but it does not work. I get module is not installed.
my questions are:
what does it mean by "installed". I have directory of files, but i haven't "installed" them anywhere.
should i be building/compiling the module to make a DLL/.so ?
does the module QML files go into the resources of the main app, otherwise where are they to be found?
my main.qml file is part of the app resources, how does the app locate the resources of the module at runtime.
Sorry, for all these questions, but the basics of these modules is just not clear. I don't understand if a "module" is just the sharing of files or is it a compiled unit.
thanks for any help.
I'll try to answer your questions:
I think installed means they are located in the proper paths, so
that they can be found at runtime
You should not necessarily create/build a QmlExtensionPlugin for that purpose. You can also use as a module plain QML files in one
directory with a qmldir describing this module. It is a matter of
distributing your code. With QmlExtensionPlugin you provide the
module compiled, if you want to hide the code.
The modules can be in resources system or as files on disk, it is up to you.
The app looks for modules in predefined paths - in your app's directory, in Qt plugins path, in QML2_IMPORT_PATH, in directories that you added using engine->addImportPath()
There are a bunch of things that can lead to a module not being loaded. You can check the following:
Module identifier in qmldir should be the same as the directory
name, where the module actually resides. For example if your module
has module identifier module Test.Module in qmldir, your module's
relative path must be Test/Module.
If it is a QML extension
plugin (shared library), make sure that plugin's directory name is
the same as plugin's name.
export QML2_IMPORT_PATH (make sure there is 2 in the name) env variable to point to directory containing your module. There is also a QQmlEngine::addImportPath method, which adds the directory to the list to lookup for plugins.
If it is a qml extension plugin (shared library), then there might be missing dependencies for it. You can check it by Dependency Walker on Windows or ldd command on Linux.
Setting QT_PLUGIN_PATH runtime variable may help to load plugins. It should point to a directory containing you plugin's directory, not the plugin's directory itself.
You can also enable traces to see what's going on while plugins are loaded for better understanding of the problem - export QT_DEBUG_PLUGINS=1 and QML_IMPORT_TRACE=1 environment variables
You can also read this link:
https://doc.qt.io/qt-5/qtqml-modules-identifiedmodules.html
In my case (I have all QML files in qrc resources) worked to add qmldir to resources also and call method addImportPath("qrc:/") of QQmlApplicationEngine.
My main.cpp looks like:
QQmlApplicationEngine engine;
engine.addImportPath("qrc:/");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
Important parts of my .pro file looks like:
RESOURCES += qml.qrc \
MyModule/mymodule.qrc
QML_IMPORT_PATH += $$PWD
My qmldir:
module MyModule
MyItem 2.0 MyItem20.qml
MyItem 2.1 MyItem21.qml
My qrc:
<RCC>
<qresource prefix="/MyModule">
<file>MyItem20.qml</file>
<file>MyItem21.qml</file>
<file>qmldir</file>
</qresource>
</RCC>
And finally my main.qml:
import QtQuick 2.5
import QtQuick.Window 2.2
import MyModule 2.0
Window {
visible: true
width: 640
height: 480
MyItem {
anchors.fill: parent
}
}
QtCreator is happy (not underlining components and imports) and module is loaded.
Hope this helps.
I want to expand on arxarian's answer - which I think is the best technique for integrating modules - but couldn't fit those thoughts in a comment, so here's a new answer.
It's important to first understand that qml modules and their associated resources are runtime entities and are assumed to separately exist at some location relative to the executable unless they're included in the application resources. By including them in the resources, they are still runtime entities, but they exist under the qrc:/ root path within the application binary. This hiding of the modules is the primary reason why I think this is the best technique, unless you want your modules to be open to revision after deployment, or to be independently deployable as precompiled plugins (i.e., in the resource storage of a dynamically linked library).
So here's my explanation of the important elements of arxarian's answer:
engine.addImportPath("qrc:/"); is needed in the C++ code prior to loading the qml to instruct the engine to look for qml modules in the application resource storage.
RESOURCES += MyModule/mymodule.qrc is needed in the project (.pro) file to add the module's files to the application resource storage.
QML_IMPORT_PATH += $$PWD in the project file tells Qt Creator to look for the module starting from the root of the project source tree. In my case I had to set this to a subdirectory (e.g., "ui/modules") because my module directories started there. The import path should include the root(s) beneath all module directories. As far as I can tell, this instruction is only for the Qt Creator IDE and does not impact the build - that's why #1 is needed.
The contents of the qmldir file is as is standard for all qml modules, but it's inclusion in the module's .qrc resource file is not intuitive until you think about what's happening with runtime storage. It needs to be in the .qrc so that it is included in the application resource storage, so that the engine can find it at runtime to define the module. <qresource prefix="/MyModule"> in the module's .qrc file defines the module subdirectory relative to the qrc:/ root in the application resource storage.
The import MyModule <version> statement in qml is now setup for success. On startup the engine will have located the module in its directory under qrc:/, parsed the qmldir file there to define the module and established the name and version from those entries.
Hopefully this helps others understand what's going on, and please let me know if I've misunderstood anything.
A similar issue cost me a bit of time so I just post it here to perhaps save the next guy some effort.
My problem was that an invisible character had sneaked into the module name. Probably through copy and paste. Here my issue:
Example error output:
MyEngine failed to load component
qrc:/qml/main.qml:53 Type MyComponent unavailable
file:///Users/<pathToProject>/MyProject/qml/MyModule/MyComponent.qml:-1 No such file or directory
It all looks fine and the path displayed is indeed the correct one. So what is wrong?
Now, copy that path to a Terminal window:
file:///Users/<pathToProject>/MyProject/qml/MyModule/<feff>MyComponent.qml
There it is, the:
"<feff>"
Solved the issue by manually retyping the component name in the qmldir file, and thus effectively deleting the invisible character.
I had the same problem and have now fixed it. I found a QML plugin for iOS. There are several things that need to be taken care of:
1. The plugin pro file needs an addition:
uri = IosTestPulgin
# this for error:
# static plugin for module “QtQuick” with name “IosTestPulgin”
# has no metadata URI
QMAKE_MOC_OPTIONS += -Muri=$$uri
# thanks from:https://github.com/wang-bin/QtAV/issues/368
2. The QML plugin qmldir file needs an additional line like this:
classname IosqmlpluginPlugin
# for ERROR: Plugin iostestqmlplugin is missing a classname entry,
# please add one to the qmldir file.
# look for qt document http://doc.qt.io/qt-5.6/qtqml-modules-qmldir.html
3 The client project pro file needs an addition like this:
ios {
IOSTestPlugin_BUNDLE.files += $$files($$[QT_INSTALL_QML]/IosTestPulgin/qmldir)
IOSTestPlugin_BUNDLE.path = IosTestPulgin
QMAKE_BUNDLE_DATA += IOSTestPlugin_BUNDLE
}
# for ios error: module is not installed
# this means external qml static plugin must add the plugin dir by manual
# in the app root dir

Qt executable naming

I'm hoping this is an easy question. I have setup an Ogre3D project in QtCreator 2.6.1 using MSVC2010. I have to setup a custom build step and I noticed that the letter 'd' is appended to the name of the compiled .exe (e.g. OrgeProgramd.exe, CoolGamed.exe)
This is not critical, I was just wondering why this happens. Is it normal? The target in the .pro file is correct. I tried building with Release and I get the same thing. Any ideas?
Look through your pro/pri files and find the line, similar to this: TARGET = $$join(TARGET,,,d). If you do - that would be the reason.

Qt How to make and install plugins?

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!

Resources