PDA

View Full Version : Cannot add new mimetype for a custom Qt Creator Plugin



yagabey
1st February 2011, 22:09
Hello,

I am trying to develop an application on Qt Creator plugin Framework. I removed all the plugins except the coreplugin. Actually I want to implement a diagram editor which uses a custom xml format as the file format. I found a document "Writing-Qt-Creator-Plugins.pdf" and took it as a reference.

So far I implemented all the interfaces(factory, editor, file,widget...). When I run Qt Creator my plugin is loaded succesfully(I can see it in plugins list) But the problem is I cannot load my specific file format(.mdv). I always get "Cannot open file..." error when I attempt.

I created mimetypes.xml document:


<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/d-editor">
<sub-class-of type="application/xml"/>
<comment>Diagram File</comment>
<glob pattern="*.mdv"/>
</mime-type>
</mime-info>

loaded it:

QString mimpath=":/diagramEditor.mimetypes.xml";
mdb->addMimeTypes((const QString&)mimpath, &errMs);


I defined constants:

const char * const C_DIAGRAMEDITOR_MIMETYPE = "application/d-editor";
const char * const C_DIAGRAMEDITOR = "Diagram File";

and implemented IFile::mimeType(), IEditor::kind() and IEditorFactory::mimeTypes().

Perhaps these may give some clue:
in mimedatabase.cpp:
*findByFile(QFileInfo&) method is returning false....
*m_typeMimeTypeMap.contains(it.key()) always return false. I can debug that those guys contain "application/d-editor" and "application/xml"
*

Core::MimeType typ = mdb->findByType(QString(DiagramEditorConstants::Constan ts::C_DIAGRAMEDITOR_MIMETYPE));
qDebug("File Type for application/d-editor = %s", qPrintable(typ.type()));
returns:
File Type for application/d-editor = application/d-editor

but

Core::MimeType type1 = mdb->findByFile( QFileInfo("D:/qtcreator-truncated-build-desktop/YeniDiagram.mdv") );
qDebug("File Type for sample.mdv = %s", qPrintable(type1.type()));
returns:
File Type for sample.mdv =

For 3 days I am trying to figure out what is going on; but i am stuck... Any idea, what may be the problem?

Thanks in advance...
Yigit

yagabey
6th February 2011, 12:52
Ok, i've figured out the problem. TextEditor.mimetypes.xml should also be added to mimemdatabase since my mimetype is a subclass of that. So by adding that mimetypes.xml, the problem is solved:


QString mimpath=":/TextEditor.mimetypes.xml";

if(!mdb->addMimeTypes((const QString&)mimpath, &errMs))
return false;