FileOpenEvent not called.
-
I have a program with a custom file format and I'm trying to get the file to open from Finder on Mac OSX using Qt 4.8. I've done this before in another program and it worked just fine. Even though I copy and pasted the code from that program (and its plist) exactly, I can't get it to work.
When I double click the file when the program is already running, it loads the file just fine. But if I click the file when the program isn't running, the program starts but doesn't load the file. In fact, the FileOpen event is never called at all. I know because I put a quit() command in there just to see if it ever reaches that part.
I've tried refreshing Launch Services, restarting finder, restarting the computer. Nothing seems to work. I don't know how relevant the code is, because the same code works in another program, and it's pretty much just copied from the instructions. But here it is in case I missed something:
Custom application class:
@#include <QFileOpenEvent>
#include "dcapplication.h"DCApplication::DCApplication(int &argc, char **argv) : QApplication(argc, argv)
{
setStyle("plastique");
}void DCApplication::loadFile(QString fileName) {
emit fileLoaded(fileName);
}bool DCApplication::event(QEvent *event)
{
switch (event->type()) {
case QEvent::FileOpen:
loadFile(static_cast<QFileOpenEvent *>(event)->file());
return true;
default:
return QApplication::event(event);
}
}
@main.cpp
@#include <QFile>#include "mainwindow.h"
#include "dcapplication.h"int main(int argc, char *argv[])
{
DCApplication a(argc, argv);QGLFormat glf = QGLFormat::defaultFormat(); glf.setSampleBuffers(true); glf.setSamples(4); QGLFormat::setDefaultFormat(glf); MainWindow w; QFile File(":/style.qss"); File.open(QFile::ReadOnly); QString StyleSheet = QLatin1String(File.readAll()); w.setStyleSheet(StyleSheet); w.show(); return a.exec();
}@
And although it never gets that far, here is the line connecting it in the main window:
@connect(qApp, SIGNAL(fileLoaded(QString)), this, SLOT(openFileFromFinder(QString)));@Is there some extra step that I don't remember doing for the other software that I need to complete? I can't imagine why it would get the signal if the program is already running, but not if Finder starts it. At least not when I am using the exact code that is in the documents, and the exact code that works elsewhere.