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)

    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;
    return QApplication::event(event);

    @#include <QFile>

    #include "mainwindow.h"
    #include "dcapplication.h"

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

    QGLFormat glf = QGLFormat::defaultFormat();
    MainWindow w;
    QFile File&#40;":/style.qss"&#41;;;
    QString StyleSheet = QLatin1String(File.readAll());
    return a.exec&#40;&#41;;


    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.

  • Nevermind. It just started working. I have no idea what I did though.

  • Moderators

    Sometimes a rerun qmake and/or a rebuild helps. Either you have done explicitly or at least through another change in code and build.
    However, no way to discover now.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.