Results 1 to 17 of 17

Thread: Opening swf file in the default browser

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

    Default Opening swf file in the default browser

    Hi,

    I used ShellExecuteW with the path to the swf file but it is not opening it. This is probably because the swf file is not associated with the browser.

    I believe to do this I would first have to know that path to the default browser and then use QProcess to open the swf file with the default browser.

    Can anyone plese tell me how to do this ?

    Thanks a lot.

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

    Cool Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    Hi,

    I used ShellExecuteW with the path to the swf file but it is not opening it. This is probably because the swf file is not associated with the browser.

    I believe to do this I would first have to know that path to the default browser and then use QProcess to open the swf file with the default browser.

    Can anyone plese tell me how to do this ?

    Thanks a lot.
    This is easy on Unix/X11:

    for KDE:

    $> kfmclient exec <filename>

    this will open the file with the default binding if at all it exists...i.e. any app that associates itself with .swf MIME type.

    for GNOME:

    $>gnome-open <filename>

    for WINDOWS:

    I can't remember at all!!

    Nupul

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    Hi,

    I used ShellExecuteW with the path to the swf file but it is not opening it. This is probably because the swf file is not associated with the browser.

    I believe to do this I would first have to know that path to the default browser and then use QProcess to open the swf file with the default browser.

    Can anyone plese tell me how to do this ?

    Thanks a lot.
    If no application is associated with the SWF file then is normal that ShellExecuteW doesn't open nothing... Have you tried it associating the swf file to a browser?

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

    Default Re: Opening swf file in the default browser

    Have you tried it associating the swf file to a browser?
    No, I did not try this because even if I associate, the user of the application will not have swf files associated with the browser.

    Is there a way by which I can know that path to the default browser?

    Thanks a lot.

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

    Wink Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    No, I did not try this because even if I associate, the user of the application will not have swf files associated with the browser.

    Is there a way by which I can know that path to the default browser?

    Thanks a lot.
    why do you need to do this? I gave you a method above. It will open the .swf file on the user's comp if at all he has some default application to do so!

    as for checking the default browser is considered....an swf file will open in any compatible browser, so you don't need to worry about this!

    and if you are really hell bent on wanting to show your application in the default browser then go through the man pages for 'kfmclient' maybe you could tweak around with certain options and get what you are looking for!

    On Windows........................... i can't think of a way to do this...maybe some one could help

    Nupul

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

    Default Re: Opening swf file in the default browser

    Unfortunately I want it for windows.

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

    Talking Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    Unfortunately I want it for windows.

    I too will wait for this soln

    if you find it out before I do, post it here! else...............................I will

    Cheers

    Nupul.

  8. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening swf file in the default browser

    Quote Originally Posted by nupul
    I too will wait for this soln

    if you find it out before I do, post it here! else...............................I will

    Cheers

    Nupul.
    The Windows ShellExecuteW() solution does exactly the same as the solutions you have provided for linux. They launch the associated application if there is already an association for that file. If the user has not yet made an association, either by creating it herself ar installing a program that makes that association, there is very little you can do about that.
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Opening swf file in the default browser

    Quote Originally Posted by Chicken Blood Machine
    The Windows ShellExecuteW() solution .....
    That's It!!!!!!!!!!

    This is what I was trying to remember for all these days!!!!! I overlooked it in the question and didn't put much thought...I thought there was something else (there isn't, right?)

    Thanks (the biggest smile.......no smiley for that!)

    Nupul

  10. #10
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening swf file in the default browser

    Well Munna did mention it quite clearly at the beginning of this thread!
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Opening swf file in the default browser

    So should I assume that what I want to achieve is just not possible ?

  12. #12
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    So should I assume that what I want to achieve is just not possible ?
    That depends. What do you mean by default browser? Default browser of what?
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Opening swf file in the default browser

    Default browser of the user's system which is running a Windows OS.

  14. #14
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    Default browser of the user's system which is running a Windows OS.
    Yes, but default browser of what? What does it browse? What is the kind of data, the file type?
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Opening swf file in the default browser

    ok, let me explain you the whole thing again.

    My application reads a text file which has paths to a few swf files on user's system and shows the list.

    Usually swf files are not associated with any application but if you open them in a browser (Internet Explorer,Firefox....) which has the flash pluing installed, the swf file will play.

    When user wants to play any of these swf files he clicks on the list item. ShellExecuteW will not work because the swf files are not associated with any application. Therefore if I know the path to the user's default broswer(IE or Firefox or what ever it is) I can use QProcess to open it.

    One solution that I found was to embedded the swf into a html file and then open it.

    But my question is that, is there a way by which I can find the path to the user's default internet browser.

  16. #16
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Opening swf file in the default browser

    Quote Originally Posted by munna
    ok, let me explain you the whole thing again.

    My application reads a text file which has paths to a few swf files on user's system and shows the list.

    Usually swf files are not associated with any application but if you open them in a browser (Internet Explorer,Firefox....) which has the flash pluing installed, the swf file will play.

    When user wants to play any of these swf files he clicks on the list item. ShellExecuteW will not work because the swf files are not associated with any application. Therefore if I know the path to the user's default broswer(IE or Firefox or what ever it is) I can use QProcess to open it.

    One solution that I found was to embedded the swf into a html file and then open it.

    But my question is that, is there a way by which I can find the path to the user's default internet browser.
    Munna,

    I understood your problem exactly as you described it. But, I don't think you understand what you are asking for. What is a 'default browser'? What you actually mean is the default program for viewing HTML files. This of course is easy to find (as you have seen) with using ShellExecuteW() on a HTML file. Why is this? becasue at some time in the past, the user associated files of type HTML with a certain browser, or more likely, the browser did it itself when it was installed.

    Now I hope you understand. There is no such thing as a default "browser", just a default program associated with a particular file type. Your problem is that there is no program associated with the swf file type. Therefore you will have to use Windows APIs to hack the registry yourself and associate it with the program used to open HTML files (this may not even work if the web browser doesn't have the plugin that you need).

    I wouldn't recommend this at all. Embedding the file in a HTML file as you have done is probably the best way to go, or bringing up the Windows dialog that prompts the user to locate a program to open a particular file type (or search the internet for a compatible program). I don't know how to do that though. Try MSDN.
    Save yourself some pain. Learn C++ before learning Qt.

  17. #17
    Join Date
    Jan 2006
    Location
    Minsk, Brest, Belarus
    Posts
    54
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Opening swf file in the default browser

    Hi! This is my old code but it works and maybe you'll find it useful:

    this class works only on Windows. It tries to launch the specified filename in this way:
    - takes the filename extention and look the associated program in the registry
    - launches this app with our file.

    This code is not final and is dirty cause it was written in the very fast way and needs to be modified. So take it as example!

    === winfileexecutor.h ===

    Qt Code:
    1. #ifndef WINFILEEXECUTOR_H_
    2. #define WINFILEEXECUTOR_H_
    3.  
    4. #include <QString>
    5.  
    6. /*!
    7. \class WinFileExecutor
    8.  
    9. \brief The WinFileExecutor class provides support to launch book in associated program.
    10. */
    11.  
    12. class WinFileExecutor
    13. {
    14. public:
    15. WinFileExecutor(const QString &fileName);
    16. virtual ~WinFileExecutor() {}
    17.  
    18. QString getKeyPath(const QString _ext) const;
    19. QString getOpenExe(const QString _keyPath) const;
    20.  
    21. private:
    22. QString _fileName;
    23.  
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    === winfileexecutor.cpp ===

    Qt Code:
    1. #include "winfileexecutor.h"
    2.  
    3. #include <qt_windows.h>
    4. #include <QMessageBox>
    5. #include <QFileInfo>
    6. #include <QProcess>
    7.  
    8. /*!
    9. How to find program associated with this file type?
    10. It's easy!
    11.  
    12. ONLY FOR WINDOWS OS!
    13. We must access regestry.
    14. The in hkcr find the decription of the extention of the file.
    15. Then we must find the description key and read the open command!
    16.  
    17. */
    18.  
    19. static QString getWindowsRegString( HKEY key, const QString &subKey )
    20. {
    21. QT_WA( {
    22. char buf[1024];
    23. DWORD bsz = sizeof(buf);
    24. int r = RegQueryValueExW( key, (TCHAR*)subKey.utf16(), 0, 0, (LPBYTE)buf, &bsz );
    25. if ( r == ERROR_SUCCESS ) {
    26. s = QString::fromUtf16( (unsigned short *)buf );
    27. } else if ( r == ERROR_MORE_DATA ) {
    28. char *ptr = new char[bsz+1];
    29. r = RegQueryValueEx( key, (TCHAR*)subKey.utf16(), 0, 0, (LPBYTE)ptr, &bsz );
    30. if ( r == ERROR_SUCCESS )
    31. s = ptr;
    32. delete [] ptr;
    33. }
    34. } , {
    35. char buf[512];
    36. DWORD bsz = sizeof(buf);
    37. int r = RegQueryValueExA( key, subKey.toLocal8Bit(), 0, 0, (LPBYTE)buf, &bsz );
    38. if ( r == ERROR_SUCCESS ) {
    39. s = buf;
    40. } else if ( r == ERROR_MORE_DATA ) {
    41. char *ptr = new char[bsz+1];
    42. r = RegQueryValueExA( key, subKey.toLocal8Bit(), 0, 0, (LPBYTE)ptr, &bsz );
    43. if ( r == ERROR_SUCCESS )
    44. s = ptr;
    45. delete [] ptr;
    46. }
    47. } );
    48. return s;
    49. }
    50.  
    51. WinFileExecutor::WinFileExecutor(const QString &fileName)
    52. : _fileName(fileName)
    53. {
    54. if (_fileName.isEmpty())
    55. return;
    56.  
    57. QFileInfo fi(_fileName);
    58. //QString ext = fi.completeSuffix();
    59. QString ext = fi.suffix().prepend(".");
    60.  
    61. QMessageBox::warning(0, ext, _fileName );
    62.  
    63. QString _prog = getOpenExe( getKeyPath(ext) );
    64.  
    65. if (_prog.isEmpty())
    66. return;
    67.  
    68. QProcess::startDetached( _prog, QStringList() << fileName );
    69. }
    70.  
    71. QString WinFileExecutor::getKeyPath(const QString _ext) const
    72. {
    73. HKEY k;
    74. int r;
    75.  
    76. QT_WA( {
    77. r = RegOpenKeyExW( HKEY_CLASSES_ROOT, reinterpret_cast<const wchar_t *>(_ext.utf16()),
    78. 0, KEY_READ, &k );
    79. } , {
    80. r = RegOpenKeyExA( HKEY_CLASSES_ROOT, _ext.toLocal8Bit(),
    81. 0, KEY_READ, &k );
    82. } );
    83.  
    84. if ( r == ERROR_SUCCESS )
    85. {
    86. s = getWindowsRegString( k, QString::null );
    87. RegCloseKey( k );
    88. }
    89. else
    90. {
    91. RegCloseKey( k );
    92. }
    93.  
    94. QMessageBox::warning(0, s, s );
    95.  
    96. return s;
    97. }
    98.  
    99. QString WinFileExecutor::getOpenExe(const QString _keyPath) const
    100. {
    101. HKEY k;
    102. int r;
    103.  
    104. QString _fullPath = _keyPath + "\\shell\\Open\\Command";
    105.  
    106. QT_WA( {
    107. r = RegOpenKeyExW( HKEY_CLASSES_ROOT, reinterpret_cast<const wchar_t *>(_fullPath.utf16()),
    108. 0, KEY_READ, &k );
    109. } , {
    110. r = RegOpenKeyExA( HKEY_CLASSES_ROOT, _fullPath.toLocal8Bit(),
    111. 0, KEY_READ, &k );
    112. } );
    113.  
    114. if ( r == ERROR_SUCCESS )
    115. {
    116. s = getWindowsRegString( k, QString::null );
    117. RegCloseKey( k );
    118. }
    119. else
    120. {
    121. RegCloseKey( k );
    122. }
    123.  
    124. QStringList lst = s.split(" \"");
    125. QString _progName = lst[ 0 ].remove("\"");
    126.  
    127.  
    128. QMessageBox::warning(0, s, _progName );
    129.  
    130. return _progName;
    131. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 9
    Last Post: 23rd August 2012, 01:01
  2. How to set default icons of different file types?
    By merry in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2008, 16:24
  3. Re: Opening Project file Issue in Edyuk
    By philwinder in forum Qt-based Software
    Replies: 6
    Last Post: 5th May 2008, 21:49
  4. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 07:51
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21

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.