0

Using Qt 5.9 I codded a spreadsheet program and then created an installer for it by Qt Installer Framework (QtIFW2.0.1). Then I sent the program to many of my friends. They installed the app on their Windows machine and now using it, but they have all have a common problem:
when they save files of the app, those files are shown as "unknown" files on Desktop.

The problem is only with the shape and appearance of the stored files not their functionality, and they are opened by the app if double clicked.

The question is, what changes in the code is needed to have the program make its files' shape/appearance shown known?
For example, we offer the code a specific shape using an image file or like that, to be mapped on the stored files and that way they are shown known.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Franky
  • 1,181
  • 2
  • 11
  • 33

1 Answers1

2

This has actually nothing to do with Qt or C++ itself. You just need to register your file extension in Windows shell, so it can be understood by other Windows components/shells.

Here is general information about File Types and File Associations under windows.

You need to make some Windows Registry entries which look like this:

example.reg:

Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Classes\myfirm.myapp.v1\shell\open\command]
    @="c:\path\to\your\app.exe \"%1\""
    [HKEY_CURRENT_USER\Software\Classes\.myextension]
    @="myfirm.myapp.v1"

Here you can read how it works in general

change myfirm.myapp.v1, .myextension and path to your .exe to your prefered names. Now Windows will know what the files with extension .myextension should be opened by your app. And if you double click on this files your app will be run with path to file as an argument. You can get it in your main() function

To set icon for your extension add Registry entry in Software\\Classes\\.myextension\\DefaultIcon and set it default value to the full path to your app, so windows can get an icon for extension from your .exe app file.

You can also do it at runtime directly in your app:

QSettings s("HKEY_CURRENT_USER\\SOFTWARE\\CLASSES", QSettings::NativeFormat);

QString path = QDir::toNativeSeparators(qApp->applicationFilePath());
s.setValue(".myextension/DefaultIcon/.", path);
s.setValue(".myextension/.","myfirm.myapp.v1");
s.setValue("myfirm.myapp.v1/shell/open/command/.", QStringLiteral("\"%1\"").arg(path) + " \"%1\"");

EDIT: One more, to do it with Qt Installer look at the answers here

Hyndrix
  • 4,282
  • 7
  • 41
  • 82
Xplatforms
  • 2,102
  • 17
  • 26
  • Thanks. I haven't read it completely but I think it wants me to manipulate the registery. So why don't I manipulate registery when I install another app? It's because that app itself manipulates the registery (by its code) not the user. Besides, assume I send the app for a normal user that isn't able to get into the registery, what can they do with the app? I try to express the issue using the plainest English sentence I can: "I don't want that I myself manipulate the registery or whatsoever, I want to manipulate the app so that it itself does that for any user, just like any other app. – Franky Sep 14 '17 at 16:59
  • Have you read my answer till the end? There is an Qt code at the end to do that. just copypast this 4lines of code it to your app code and change "myfirm.myapp.v1" and ".myextension" to your values... – Xplatforms Sep 15 '17 at 07:17
  • OK, I read your answer, thanks. Should I use both the script file code in the other thread and also that code you've written here? I have many files and functions in the program, and two functions that I use *QSettings* there named *void MainWindow::readSettings()* and *void MainWindow::writeSettings()*. Please take a look [at the code](https://www.dropbox.com/s/ebv4qvol49rrqd3/SP.rar?dl=0). – Franky Sep 15 '17 at 18:07
  • I used both that code and also the script file's code but there isn't any icon on my files yet! :-( – Franky Sep 16 '17 at 09:41
  • What's that `v1`? – Franky Sep 17 '17 at 12:38
  • I have added quotes around the app path in your code snipped because else it will fail with paths which do contain spaces. – Hyndrix Oct 30 '21 at 17:17