PDA

View Full Version : how can i associate my program with a specific file?



mismael85
11th February 2008, 15:39
hi everybody;
lately i developed a simple program that handles text files on windows .
i want to know how to make my program the default one for txt file type?

jpn
11th February 2008, 16:30
Qt doesn't offer any direct way to do this. You will have to use WinAPI directly or modify registry with help of QSettings.

mismael85
11th February 2008, 17:02
yes, i know.
but how can i use QSettings to do that.
note that i know how to use QSettings but i do not know which key sholud i change.
and thank you for your co-operation.

bender86
12th February 2008, 12:33
See http://msdn2.microsoft.com/en-us/library/bb776847.aspx

Briefly, you should add a .ext key to HKEY_CLASSES_ROOT, then set its default value to extfile. Then add a extfile key to HKEY_CLASSES_ROOT, with subkeys DefaultIcon (default value = icon) and shell/open/command (default value = "/path/to/app %1").
See .txt and txtfile keys for an example.

THRESHE
13th February 2008, 14:55
Does anybody know how to open files in your program when it runs and user double clicks on the file which is associated with your program ? :confused:

bender86
13th February 2008, 15:17
Does anybody know how to open files in your program when it runs and user double clicks on the file which is associated with your program ? :confused:

Do you mean when user double clicks on a file and its associated application is already running?
You have to use some interprocess communication system. Basically, when your app starts, it must check if another instance is running, and if yes it must send it a message (i.e. open a new file).
You can use sockets, or lock files, or platform specific ways (i.e. mutexes and mailslots on windows).

THRESHE
13th February 2008, 15:33
Do you mean when user double clicks on a file and its associated application is already running?
Yes I do mean that :)

You have to use some interprocess communication system. Basically, when your app starts, it must check if another instance is running, and if yes it must send it a message (i.e. open a new file).
You can use sockets, or lock files, or platform specific ways (i.e. mutexes and mailslots on windows).
Thanks for reply but I've just found the way how to do it here http://www.qtcentre.org/forum/f-qt-programming-2/t-qt-app-run-once-11824.html
Honestly I thought that I should do it the way it is described in that topic. But I thought that Qt already has this feature...