0

I am creating an application using Qt. The files saved from my application have their own file format & extension. I want to associate this file format with my application. So, when a user double clicks say myfile.ext then the OS should automatically run my application (how to specify its path?) & pass path of file as an argument.

I have only used Windows until now so I am talking in terms of it. I dont know how other OS's behave. Any guidance for the same would be helpful?

PS: Even though I am using Qt which apparently has no special functionality to do what is asked here (AFAIK), it would be awesome to know how to do this in standard C++.

Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80
Cool_Coder
  • 4,888
  • 16
  • 57
  • 99
  • 1
    I think you can find the answer in the answers to this post: [Create registry entry to associate file extension with application in C++](http://stackoverflow.com/questions/1387769/create-registry-entry-to-associate-file-extension-with-application-in-c?rq=1) – jpw Jul 02 '13 at 12:03
  • 1
    a few pointers there: http://qt-project.org/forums/viewthread/4810/ – SirDarius Jul 02 '13 at 12:05

2 Answers2

2

For Windows see the MSDN page "File Type Handlers" for how to register file type handlers.

On many popular Linux desktops, so-called .desktop files are used to define what application to use for opening a file. See the "Desktop Entry Specification" for the structure of those .desktop files. They are quite simple really, changes are you can just take an existing file from any of the popular Linux desktop environments (e.g. KDE) and modify it a bit.

Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
1

It's a function of the OS, not of the C++ language. You'll need to figure it out on each platform you are supporting.

John3136
  • 28,809
  • 4
  • 51
  • 69
  • 1
    What is sad about it? You cannot expect that language as C++ would support features of every OS it can run on. – jnovacho Jul 02 '13 at 12:04
  • Not if you think about it: Your program isn't running yet, so nothing in your code can do anything about it. It has to be an OS feature. – John3136 Jul 02 '13 at 12:04
  • @jnovacho, actually I wanted do this during the first run of my application; since my application does not have a installer. – Cool_Coder Jul 02 '13 at 12:09