I am using Qt C ++ for my MacOS application (10.11), but I cannot get it to accept filedrop.
Here's the Info.plist
file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.1">
<dict>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleGetInfoString</key>
<string>Created by Qt/QMake</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleExecutable</key>
<string>QParser</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.QParser</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>csv</string>
<string>public.comma-separated-values-text</string>
<string>comma-separated-values-text</string>
<string>txt</string>
<string>text</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
In my main window I installed eventFilter
, but the event is not fired (it introduces an event filter, but not for the event QEvent::FileOpen
).
I checked the thesis of the links, but this did not help:
Here's mine MainWindows.cpp
:
#include <QMessageBox>
#include <QProcess>
#include <QFileOpenEvent>
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setAcceptDrops(true);
this->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_goButton_clicked()
{
checkFile();
}
bool MainWindow::eventFilter(QObject * sender, QEvent *event)
{
switch (event->type()) {
case QEvent::FileOpen:
{
event->accept();
qDebug() << "Event File Open";
ui->lineEdit->setText(static_cast<QFileOpenEvent*>(event)->file());
checkFile();
break;
}
case QEvent::DragEnter:
{
event->accept();
qDebug() << "Event DragEnter";
break;
}
case QEvent::Drop:
{
event->accept();
const QMimeData* mimeData = static_cast<QDropEvent *>(event)->mimeData();
qDebug() << "Event Drop";
if (mimeData->urls().length() == 1) {
QString fileName = mimeData->urls().first().toLocalFile();
qDebug() << fileName;
}
break;
}
default:
return false;
}
return true;
}
void MainWindow::checkFile()
{
}
Where should I dig for it to work?
source
share