PDA

View Full Version : Opening documents on Windows



fober
8th February 2011, 14:54
Hi,

On Mac, you can open a document directly from the finder (see Opening_documents_in_the_Mac_OS_X_Finder (http://www.qtcentre.org/wiki/index.php?title=Opening_documents_in_the_Mac_OS_X_ Finder) )
It relies on a QFileOpenEvent class which is currently supported for Mac OS X only.
How can I get an equivalent on windows ? (i.e. the ability to drop a file on the application icon to open it).
Thanks in advance for any help.
--
Dom

agarny
8th February 2011, 16:08
If all you want on Windows is to be able to drag and drop one or several files on your application, then you need to handle the arguments passed to your Qt application. Just try the following:


#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QMessageBox>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QMessageBox::information(NULL, "Arguments:", a.arguments().join(" | "));

MainWindow w;
w.show();

return a.exec();
}

nightghost
8th February 2011, 16:27
I think he wants to register a file type for his application. You can do this with your installer. E.g. WIX (http://stackoverflow.com/questions/2772452/how-to-associate-application-with-existing-file-types-using-wix-installer) or
NSIS (http://nsis.sourceforge.net/File_Association) or do it manual by modifying the registry (http://msdn.microsoft.com/en-us/library/ee872123%28v=VS.85%29.aspx).

fober
8th February 2011, 16:48
Thanks a lot ! :)
That's exactly what I need

Thanks a lot ! :)
That's exactly what I need


I think he wants to register a file type for his application. You can do this with your installer. E.g. WIX or NSIS or do it manual by modifying the registry.

That's another problem. I just want to support files dropped on the application icon.
(and it works now using the application arguments())

wysota
8th February 2011, 21:43
Thanks a lot ! :)
That's exactly what I need

Thanks a lot ! :)
That's exactly what I need



That's another problem. I just want to support files dropped on the application icon.
(and it works now using the application arguments())

Note that this is a different situation from the one you describe in your original post. Mac allows you to drop a document on an icon of an application that is already running, what you mean is a situation when you want to launch a new instance of your application passing it the document to open.

fober
8th February 2011, 22:36
Note that this is a different situation from the one you describe in your original post. Mac allows you to drop a document on an icon of an application that is already running, what you mean is a situation when you want to launch a new instance of your application passing it the document to open.

You're right ! Let's say that I get half of the desired behavior (not so bad :))
Any tip on getting the second half (dropping a file when the application is already running) is welcome !

However, I don't think that's usual on Windows : most of the time, when you drag a file to the tasks bar over a running application, it brings the application window to foreground and you can next drop the file to the window, which has cross-platform support in Qt. (note that I'm not an expert in windows)

wysota
8th February 2011, 23:04
You're right ! Let's say that I get half of the desired behavior (not so bad :))
Any tip on getting the second half (dropping a file when the application is already running) is welcome !
What do you want to drop it on? There is no direct Windows equivalent of what's available for Mac.

fober
9th February 2011, 07:48
What do you want to drop it on?
A document file, actually describing the content of a window. For more information about what I'm doing, see the INScore (http://inscore.sourceforge.org) project.


There is no direct Windows equivalent of what's available for Mac.
I guess so. That's why the second half is no so important. And I think it's better to stick to the platform standard behavior.

wysota
9th February 2011, 08:53
A document file, actually describing the content of a window. For more information about what I'm doing, see the INScore (http://inscore.sourceforge.org) project.
I don't understand what "dropping a file on a document file" means.

fober
9th February 2011, 09:40
I don't understand what "dropping a file on a document file" means.
Sorry ! It looks like I've not been very clear. I was speaking about dropping a document on the application icon, and this document is basically describing the content of a scene.

wysota
9th February 2011, 11:34
I was speaking about dropping a document on the application icon, and this document is basically describing the content of a scene.

On the application icon while the application is running? Again, Windows doesn't have a concept of such a thing...

fober
9th February 2011, 22:01
On the application icon while the application is running? Again, Windows doesn't have a concept of such a thing...
I know, that's why I feel satisfied with half of the Mac OS behavior (see above)

wysota
9th February 2011, 22:27
It's not half of Mac's behaviour. It's a totally different concept.