Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, February 2007
How to get my app to open a file when it is double-clicked in Explorer (Qt 3.3)


Message 1 in thread

I have searched the archives and docs unsuccessfully. Could someone  
please point me to information on how to get my Qt application to  
handle an 'open' event sent to it by Explorer when the user double- 
clicks a file on the desktop (say). I am using Windows XP, and have  
managed to set up the registry so that double-clicking a file with  
appropriate filename extension causes my application to launch. But  
it does not automatically open the file, like a well-behaved program  
should. I believe this is handled better in Qt 4, but I am stuck with  
Qt 3.3 for now.

Thanks,

John.

--
 [ signature omitted ] 

Message 2 in thread

John Clements schrieb:
>
> I have searched the archives and docs unsuccessfully. Could someone 
> please point me to information on how to get my Qt application to 
> handle an 'open' event sent to it by Explorer when the user 
> double-clicks a file on the desktop (say). I am using Windows XP, and 
> have managed to set up the registry so that double-clicking a file 
> with appropriate filename extension causes my application to launch. 
> But it does not automatically open the file, like a well-behaved 
> program should. I believe this is handled better in Qt 4, but I am 
> stuck with Qt 3.3 for now.
>
> Thanks,
>
> John.
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
Hi,

this is more related to configure the windows correctly...
The usuall way when you connect a filetype to an application is to give 
the filename to the application as argument with "%1" after the call.
This is set in the Explorers "Folder Options"->"File Type", select the 
default action and append the "%1" behind your application.
Now you get the filename in argv[1] (be sure to check if argc > 1, 
otherwise you read from an invalid adress)

Sorry if the names in the explorer don't fit exactly, I have the german 
windows installed, so I had to translate back...

Good luck,
Daniel

-- 
 [ signature omitted ] 

Message 3 in thread

> -----Original Message-----
> From: Daniel Walz [mailto:walz@xxxxxxxx]
> Sent: Thursday, February 08, 2007 8:22 AM
> To: Qt Interest list
> Cc: John Clements
> Subject: Re: How to get my app to open a file when it is
double-clicked in
> Explorer (Qt 3.3)
> 
> John Clements schrieb:
> >
> > I have searched the archives and docs unsuccessfully. Could someone
> > please point me to information on how to get my Qt application to
> > handle an 'open' event sent to it by Explorer when the user
> > double-clicks a file on the desktop (say). I am using Windows XP,
and
> > have managed to set up the registry so that double-clicking a file
> > with appropriate filename extension causes my application to launch.
> > But it does not automatically open the file, like a well-behaved
> > program should. I believe this is handled better in Qt 4, but I am
> > stuck with Qt 3.3 for now.
> >
> > Thanks,
> >
> > John.
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
with
> > "unsubscribe" in the subject or the body.
> > List archive and information:
http://lists.trolltech.com/qt-interest/
> >
> Hi,
> 
> this is more related to configure the windows correctly...
> The usuall way when you connect a filetype to an application is to
give
> the filename to the application as argument with "%1" after the call.
> This is set in the Explorers "Folder Options"->"File Type", select the
> default action and append the "%1" behind your application.
> Now you get the filename in argv[1] (be sure to check if argc > 1,
> otherwise you read from an invalid adress)
> 
> Sorry if the names in the explorer don't fit exactly, I have the
german
> windows installed, so I had to translate back...
> 
> Good luck,
> Daniel
> 
There are two issues.  One, a double click to open the app the first
time, which is usually command line driven. (As stated byt Daniel.

Then there is the "open this file as well" into currently open
application.  Which requires some win32 event processing.  I have code
somewhere that did it, but not for a QT app... If I can find it, Ill
post it.

Scott

--
 [ signature omitted ] 

Message 4 in thread

> Then there is the "open this file as well" into currently open
> application.  Which requires some win32 event processing.  I have code
> somewhere that did it, but not for a QT app... If I can find it, Ill
> post it.

For commercial Qt developers, theres QtSingleApplication from the Qt 
Solutions for that. Works very well.

Martin

-- 
 [ signature omitted ] 

Message 5 in thread

> From: Martin Gebert [mailto:Martin.Gebert@xxxxxxxxxxxxxxxxxxxxxxxxxxx]
> Sent: Thursday, February 08, 2007 8:42 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: How to get my app to open a file when it is
double-clicked in
> Explorer (Qt 3.3)
> 
> > Then there is the "open this file as well" into currently open
> > application.  Which requires some win32 event processing.  I have
code
> > somewhere that did it, but not for a QT app... If I can find it, Ill
> > post it.
> 
> For commercial Qt developers, theres QtSingleApplication from the Qt
> Solutions for that. Works very well.
> 
> Martin
> 
Little bit different... Windows (not cross platform) can use COM to send
an event to an app to open a file. However, you could definitely modify
the QtSingleApp to send in the new command line parameters to open them
up as well... 

Currently, QtSingleApp basically says, "Does the singleton already
exist?  Yes, send a message to it, then exit... No... Start up"

Scott

--
 [ signature omitted ] 

Message 6 in thread

Scott Aron Bloom schrieb:
> ...
> Currently, QtSingleApp basically says, "Does the singleton already
> exist?  Yes, send a message to it, then exit... No... Start up"

And this very message can well be saying something like "Since you are
already running, open this file for me".

Once the already running application receives this message it calls the
appropriate "Open" functionality with the file path argument contained
in the message.

Works very well, we have just implemented that ourselves with
QtSingleApplication. Off course it requires a bit of coding on the
application side (such as parsing the messages and extracting the proper
arguments). I don't know the details of our implementation, but it's doable.

Cheers, Oliver

--
 [ signature omitted ] 

Message 7 in thread

Thanks for all the helpful advice. I've implemented and tested a solution 
based on QtSingleApplicaton - here is the code...
int main( int argc, char **argv )
{
 QtSingleApplication app( "AxoGraph X", argc, argv );

 // check whether another instance of this application is already running
 if ( app.isRunning() )
 {
  // check whether user double-clicked an AxoGraph file in Windows Explorer
  if ( argc > 1 )
  {
   // send the file path to the already running instance of AxoGraph
   QString filePath( argv[ 1 ] );
   app.sendMessage( filePath );
  }
  return 0;
 }

 app.initialize();

 // catch the file path message when a second instance of AxoGraph X is 
launched, and open the file
 QObject::connect( &app, SIGNAL( messageReceived( const QString& ) ), &app, 
SLOT( openGraphFile( const QString& ) ) );

...snip...


 if ( argc > 1 )
 {
  for ( int i = 1; i < argc; i++ )
  {
   QString pathName( argv[ i ] );
   app.openGraphFile( pathName );
  }
 }




--
 [ signature omitted ]