Drag&drop of a local file does not work under Ubuntu - qt

I have a list of local files in my app. I'm trying to add the functionality to drag and drop them to arbitrary location on the file system (e.g. drag&drop from my app to Files app).
All is working fine under Windows and macOS.
Ubuntu - does not work (nothing happens). I suspect there is something to do with the Drag.mimeData.
Example of the code I'm using:
Item
{
id: root
property string fileUrl: "file:///home/user/Downloads/index.html"
Drag.active: mouseArea.drag.active
Drag.mimeData: {"text/uri-list": root.fileUrl}
Drag.dragType: Drag.Automatic
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: root
}
}
Addition #1. I was using Qt 5.12.12. Tested under Qt 6.4.1 - works fine now. Instead of two things:
It seems it copies files instead of moving them.
Drag&drop to Desktop does not work. Workaround: open Files app, open Desktop location there, and then d&d from my app to the Files app.

Related

QtQuick.LocalStorage dont work properly with qmlscene from Qt Designer Studio

When I run Qmlscene preview from Qt Designer Studio trial , for standart example project (Clock ) which using QtQuick.LocalStorage it dont work. Log showing Error: LocalStorage: can't create path C:\Users\leo\AppData\Local\QtProject\QtQmlViewer\QML\OfflineStorage\Databases
from LocalStorage.openDatabaseSync(...) function.
Explored Qt sources i found source of localstorage plugin where was this part
QString basename = args->v4engine()->qmlEngine()->offlineStorageDatabaseFilePath(dbname);
QFileInfo dbFile(basename);
if (!QDir().mkpath(dbFile.dir().absolutePath())) {
const QString message = QQmlEngine::tr("LocalStorage: can't create path %1").arg(QDir::toNativeSeparators(dbFile.dir().absolutePath()));
V4THROW_SQL2(SQLEXCEPTION_DATABASE_ERR, message);
}
QString dbid = dbFile.fileName();
bool created = false;
QString version = dbversion;
QSqlDatabase database;
So I think there is some problem to open/create database file on default path for qt projects by qmlscene. I cant change default path and cant set offlineStorage(path) becouse i have not access to C++ code (its .qmlproject).
When I run project (not using menu item "QML Preview") or build it with C++ qmlengine loader its working normal with localstorage, but when i try to preview via QML scene tool from Qt Design Studio it show error.
Have somebody ideas how fix it or other way to use localstorage in QMLscene tool ?
Problem is bug and not decided. I found new way to store local data by write wrapers for Qt.lab.settings instantiated in Singleton qml file.
Why not just creating a bugreport?

Qt/Qml: how to include map tiles for offline usage?

I need to include offline tiles (slippy map) into a Qt/Qml mobile application that mainly runs on Android and iOS.
The only well-documented and working solution I found is the commercial Esri Arcgis Runtime for Qt. However, creating tile packages requires using the Arcgis stack, either desktop or server (please correct me if I am mistaken).
https://developers.arcgis.com/qt/
I am looking for an open source and easy to use alternative.
QtLocation has just been improved in Qt 5.5, but there seems to be no out of the box solution for offline tile packages there:
http://doc-snapshots.qt.io/qt5-5.5/qtlocation-index.html
I know this answer is late, but I had the same challenge with client supplied offline maps on Linux
You need to create the directory structure for your map tiles. As I used openstreetmaps I copied the directory structure that they use i.e. root/zoom_level/area_level_1/area_level_2/tile.png
e.g. :
~/osmTiles/12/3820/2078.png
I used marble (https://marble.kde.org/install.php?) to download the map tiles into the correct directory tree (cached), which I then copied to the target hardware and replaced the osm tiles with the client's .png files
I then used npm from node.js to install http-server and hosted the root tile directory as an http server at http//localhost:port (this answer explained it very well: https://stackoverflow.com/a/12905427/5452614)
e.g. :
http-server ~/osmTiles -p 8080
which served osmTiles on http//127.0.0.1:8080
finally I modified the standard QML Plugin thusly
Plugin {
id: osmPlugin
name: "osm"
PluginParameter { name: "osm.useragent"; value: "My Company Name" }
PluginParameter { name: "osm.mapping.host"; value: "http://127.0.0.1:8080/" }
PluginParameter { name: "osm.mapping.copyright"; value: "MyCompany" }
}
where I told QML where to look for my offline tiles. I had to specify that the map should be a custom map, which was harder. Through trial and error I found that supportedMapTypes[7] is custom map. I don't know why, but that's just how it worked out
Map{
plugin: osmPlugin
activeMapType: supportedMapTypes[7]
}
#Marco Piccolino, following our conversation from this other thread, here's the detailed workaround I've found so far, using only QtLocation, an offline tile cache, and a simple http server:
You need to place your png tiles into a folder tree like this: ".../tiles/1.0.0/sat/{z}/{x}/{y}.png", cf this link
You have to run an http server on that folder (you might want to use this command: sudo python -m SimpleHTTPServer 80)
You will have to edit your hosts file to map the following domain to your server's IP address (most probably 127.0.0.1): otile1.mqcdn.com. This trick is quite dirty but as this url is hardcoded inside the QtLocation OSM plugin we don't really have much of a choice with the current available QML API.
Finally the easiest part, in the QML code you should have something like this:
Plugin {
id: mapProvider
name: "osm"
}
Map {
anchors.fill: parent
plugin: mapProvider
gesture.enabled: true
activeMapType: supportedMapTypes[1]
}
Using offline maptiles is now possible through the ArcGIS Runtime library, starting from version 10.2.6:
https://developers.arcgis.com/qt/qml/api-reference/class_tiled_map_service_layer.html

Qt Installer Framework - Create shortcut in Start Menu for all users

With the installer framework I would like to create an installer for my application.
The application is installed by the administrator on the PC. The application is then used by different users.
In the installer I create shortcuts from executable to start menu.
This is accomplished in the installscript.js by the command:
component.addOperation(“CreateShortcut”, “#TargetDir#/application.exe”,
“#StartMenuDir#/Name of Application.lnk”, “workingDirectory=#TargetDir#”);
The problem now, is that the installer creates shortcut in the start menu only for the current user, e.g. the Administrator.
Also, the uninstall program is visible only for the current user. When I log with another user, the application is not visible in the start menu.
How is it possible to generate a shortcut, which is visible in the start menu for all users?
Try
component.addOperation("CreateShortcut", "#TargetDir#/application.exe", "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\<Name of Application>.lnk");
In fact, there is a variable AllUsersStartMenuProgramsPath available but I have just tried it and it seems to be broken. Links are put in C:\ by using it.
Like installer.value("os"), you should use installer.value("AllUsersStartMenuProgramsPath") in your script.
See the lastest documentation : http://doc-snapshot.qt-project.org/qtifw-master/scripting.html
I think a bug should be opened on their bug tracker : https://bugreports.qt-project.org/secure/Dashboard.jspa
This works for me:
Component.prototype.createOperations = function()
{
component.createOperations();
console.log("creating start menu entries");
if (systemInfo.productType === "windows") {
component.addOperation("Mkdir", "#StartMenuDir#")
component.addOperation("CreateShortcut", "#TargetDir#/README.txt",
"#StartMenuDir#/README.lnk",
"workingDirectory=#TargetDir#",
"iconPath=%SystemRoot%/system32/SHELL32.dll",
"iconId=2", "description=Open README file");
}
}
Note that the script creates the according start menu directory before creating the shortcuts.

How to open a particular file with my QT application on Mac when i double click the file?

I'm finding no way how to open a specific file format which can be opened by my Qt app automatically(when i double click the file).Please let me know how to do this.
Thanks!
You need to set up your Information Property List file (Info.plist) in your application bundle to identify files that can be opened by your app. See http://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Introduction/Introduction.html
Specifically, set the CFBundleDocumentTypes key: add items, the file extension and the role of your application (does it edit, view, etc the file).
After you have done this, finder will need to reload the plist. Then you will be able to choose to open files of that type with your application.
In your application, you will need to subclass QApplication and set up a response for QEvent::FileOpen. More information on doing that was given in Qt Quarterly Issue 18.

How to specify the location for FileReference.browse() in Flex

I have a requirement to select a file from fileReference.browse(), but I want to browse a file to specific location say D:\Dir\file instead of the OS specific (The dialog box is native to the user's operating system).
Is it possible?
Thanks in Advance-
Since you're using File, I'm assuming you're using the Air runtime. To do this, you just need to set the path in the file constructor before you browser; like this:
var file:File = new File(somePath);
file.browse();
The only problem with this is that if you set it as an absolute path (like say, "c:\Users\SomeUser"), it might not work on Macs or Linux computers. Be sure to use some of the File class' built in static properties when you can, like these:
File.applicationStorageDirectory—a storage directory unique to each installed AIR application
File.applicationDirectory—the read-only directory where the application is installed (along with any installed assets)
File.desktopDirectory—the user's desktop directory
File.documentsDirectory—the user's documents directory
File.userDirectory—the user directory

Resources