使Qt/C ++程序显示Windows上已知的文件类型 [英] Make a Qt/C++ program show its file types as known on Windows

查看:110
本文介绍了使Qt/C ++程序显示Windows上已知的文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Qt 5.9,我编写了一个电子表格程序,然后通过 Qt Installer Framework (QtIFW2.0.1)为它创建了一个安装程序.然后,我将该程序发送给了许多朋友.他们在Windows机器上安装了该应用程序,现在正在使用该应用程序,但是他们都有一个共同的问题:
当他们保存应用程序的文件时,这些文件在桌面上显示为未知"文件.

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.

推荐答案

这实际上与Qt或C ++本身无关.您只需要在Windows Shell中注册文件扩展名,即可被其他Windows组件/Shell理解.

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.

以下是有关在Windows下.

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

您需要输入一些类似于以下内容的Windows注册表项:

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

example.reg:

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

myfirm.myapp.v1.myextension以及.exe的路径更改为您的首选名称. 现在,Windows将知道您的应用程序应打开哪些扩展名为.myextension的文件.如果双击该文件,您的应用程序将以path to file作为参数运行.您可以在main()函数

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

要为扩展名设置图标,请在Software\\Classes\\.myextension\\DefaultIcon中添加注册表项,并将其默认值设置为应用程序的完整路径,以便Windows可以从.exe应用程序文件中获取扩展名图标.

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);
    s.setValue(".myextension/DefaultIcon/.",QDir::toNativeSeparators(qApp->applicationFilePath()));
    s.setValue(".myextension/.","myfirm.myapp.v1");
    s.setValue("myfirm.myapp.v1/shell/open/command/.", QDir::toNativeSeparators(qApp->applicationFilePath()) + " %1");

再做一次,用Qt Installer查看答案

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

这篇关于使Qt/C ++程序显示Windows上已知的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆