File Browser with context menu to unzip files
-
My QT tool downloads zip files. I am using a QListView with QFileSystemModel to display those zip files. Now I want the user to be able to unzip those files. So, on right click on the zip file, the user should get the same context menu actions that he gets when he right clicks on the Windows File explorer.
I think I can get this with a QFileDialog, but QFileDialog expects the user to select files, but I just want to facilitate the user to unzip the files.
-
@mahesh_j said in File Browser with context menu to unzip files:
I think I can get this with a QFileDialog, but QFileDialog
I would say https://doc.qt.io/qt-5/qmenu.html
-
@jsulm said in File Browser with context menu to unzip files:
I would say https://doc.qt.io/qt-5/qmenu.html
But I don't know what actions to add to the QMenu. So I am trying to get the Context menu displayed by the File explorer as shown in the image below. Is that possible? Or can I identify the default program for unzipping the files (7zip in my case) and invoke 7zip.exe from the QMenu?
-
@mahesh_j
I am just going to throw one comment in. Your end users may not have7zip.exe
, there are many alternative ways to zip/unzip, it may be build into the OS/File Manager.You could try instead asking the OS to Open the Zip file, but that is likely to produce a window onto the contained files list, up to you if that is what you want.
If you are only interested in unzipping, you could look at implementing that your in your Qt app. See e.g. https://forum.qt.io/topic/74306/how-to-manage-zip-file.
-
@mahesh_j said in File Browser with context menu to unzip files:
I cannot use any 3rd party libraries due to licensing issues.
Up to you, zlib encoders/decoders are free/open source.
How do I ask the OS to Open the zip files?
https://doc.qt.io/qt-5/qdesktopservices.html#openUrl
As I say, this is only going to use the default Open verb. It won't know to do an unzip to directory. For that you would need some nasty native Windows calls, outside of Qt.If you wish to re-attempt the "context menu" approach, you could look at
https://forum.qt.io/topic/29219/is-it-possible-to-call-system-shell-context-menu-for-a-file-folder-from-qt-app
https://stackoverflow.com/questions/21206917/how-to-get-a-context-menu-for-file-system-actions-in-qt
where you will see you would need to go down a native WinAPI route. -
@mahesh_j said in File Browser with context menu to unzip files:
But I don't know what actions to add to the QMenu
The actions you need. You have to create such a pop-up menu.
Take a look at http://quazip.sourceforge.net/