Results 1 to 10 of 10

Thread: Associating file extensions

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Associating file extensions

    Anyone know how to programatically associate a file extension with a app? I searched the web a bit but didn't find anything relevant...

    I'd need tips to do that under Win, Linux and Mac...
    Current Qt projects : QCodeEdit, RotiDeCode

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Associating file extensions

    What do you mean? You want to register a file type in your operating system? If so, I don't think this is an appropriate forum for such question. Especially that it has no relation to Qt.

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Associating file extensions

    I thought it could have...
    I find a static functions in QSettings that was called : registerFormat()
    It sounded nice but it finally appeared to be a way to create another setting storage format (the built-in ones being INI, system registery under win, and some xml stuff under mac).
    I am very disappointed that there are no nice way to do it under Qt and I agree with you, this is not the right place : move it to c++ programming...
    Current Qt projects : QCodeEdit, RotiDeCode

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Associating file extensions

    I meant more that it is not the right site to ask that question. Nupul already asked something simmilar here (you can find his posts about it) and did not come to any obvious solutions. Each window manager (or maybe desktop manager, I don't know) has its own system for keeping those associations.

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Associating file extensions

    I am not sure but I think the installer that you use to deploy your application does the job of associating file extensions.

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Associating file extensions

    Two obvious facts :
    - Window$ provides some way to do that but the only apps I found providing a run-time file association dialog (that would need such a facility) weren't Open Source...
    - KDE and Gnome are Open Source and the file association code could be borrowed if portable but I don't feel like browsing megs of source code and linking to KDE or Gnome libs is unacceptable for a cross-platform and lightweight project...

    Current Qt projects : QCodeEdit, RotiDeCode

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Associating file extensions

    Quote Originally Posted by munna
    I am not sure but I think the installer that you use to deploy your application does the job of associating file extensions.
    Linux doesn't use any installer and I'd like to provide dynamic association ( the user could choose what extension to associate)
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #8
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Associating file extensions

    Quote Originally Posted by fullmetalcoder
    Anyone know how to programatically associate a file extension with a app? I searched the web a bit but didn't find anything relevant...

    I'd need tips to do that under Win, Linux and Mac...
    well as wysota mentioned...i've already put forth this doubt...and here's the answer

    on KDE you have need to look in $XDG_DATA_DIR environ variable...this is where all the apps are installed...

    eg: /usr/share/applications

    look in mimeinfo.cache in this folder...
    you will find a list of file formats and the corresponding apps that can be used for opening them i.e. ".desktop" files that will be found in the same directory.

    Now if you want to associate a particular extension with an app you need to add the relevant details to the mimeinfo.cache and provide the apt .desktop file for handling it.

    on GNOME you have a file by the name gnome-application-registry (something similar )
    where you store the similar type of data. (use the locate tool to find a file of this name)

    if you want more (rather lots more info...i'can mail them to you later...)

    There is no need to look in the sources...just go on www.freedesktop.org and look for shared-mime-info-spec.....you'll get all the info you need (only if you read that with some concentration and an open mind )

    Nupul

  9. The following user says thank you to nupul for this useful post:

    fullmetalcoder (10th May 2006)

  10. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Associating file extensions

    Interesting but, as you've already played with that, have you some code snippets ??? And what about Mac and Win? No info at all???
    Current Qt projects : QCodeEdit, RotiDeCode

  11. #10
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Associating file extensions

    Quote Originally Posted by fullmetalcoder
    Interesting but, as you've already played with that, have you some code snippets ??? And what about Mac and Win? No info at all???

    hmmm...I took another work around in linux...

    for KDE I used "kfmclient"

    for GNOME i used "gnome-open"

    just pass the --help as an arguement to see how to use the system

    Now as for working for associating a file is concerned...you need to do this:

    1. download the latest freedesktop-mime-database.
    2. create your own file following the standard and add it to database
    3. run update-mime-database command
    4. run update-desktop-database command
    so you see there is technically no code snippet just a series of commands...

    now re-read the info-spec i pointed out previously....you'll understand more completely...what i just said will act as a glue to merge all the not-so-clear spec

    Now for Windows: You'll have to play with MFCs/Win32 API for this...look through the docs...am not very well versed this But here is the shortcut....create a custom extension, open it through explorer...and choose app to open that file!!!!....you could also physically do it by setting the "file type" from the tool>options etc....you know the story)

    MAC: hmmmm well MAC was a closed source system...they have now started to release out the API, so try getting your hands on it. I haven't used MAC much, but from what i know, it's a harrowing task to find the API...but i think some googling around would help...

    NOTE: The concept of MIME types is present in all systems (i.e. all systems are merging towards this)...try exploiting this...

    in one of the threads by munna, he asked how to open a a .swf by using the default app...here's the link....someone put a code snippet that was damn good...it could be of use to you...

    here's the link:

    http://www.qtcentre.org/forum/showthread.php?t=2029

    see how the registry is accesed using Qt and you could use it to your benefit!!

    Nupul

Similar Threads

  1. Can you specify a file engine?
    By skimber in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2008, 15:54
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  3. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Associating icon with a file type
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2006, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.