Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Creating custom mime types



  • Hi,

    I am trying to create some custom mime types that I will be using within my application. However, there doesn't seem to be an easy mechanism to add custom mime types to the QMimeDatabase in a portable way.

    Is there any reason why this class doesn't have a load function which takes as input an XML string with mime type definitions that can be added to the mime types that exist in the database?

    I don't need these mime types to be persistent, they need to exist only while my application is running.

    Regards,


  • Lifetime Qt Champion

    Hi
    I think the reason is that runtime only MimeTypes are not that common.
    But this is a user forum so its purely a guess.


  • Lifetime Qt Champion

    Hi,

    Out of curiosity, how will you use these mime types ?



  • @SGaist

    Hi, so basically my application is composed of a whole load of plugins and I expect eventually users will add their own.

    I have notions of document editor plugins, these support existing mime types such as (application/pdf) but also custom types of documents that are defined in my application (e.g. mind maps, org charts, etc). I want a generic way of asking a plugin what document types it supports, including vendor specific ones.

    I have reverted to using strings for the moment instead of mime types, because I can create them for my vendor specific mime types. And it's too much hassle to install them on the system.

    In my particular scenario it would be ideal if I could load the additional vendor specific mime types from an xml resource in the application. But if there was an API to add additional mime types in an easy way then that would be fine too.

    Regards,


  • Lifetime Qt Champion

    AFAIK, mime types are defined as string. As for using QMimeDatabase, there's a description in the details of the class on how to support new mime types so you likely need to explore that part for the OSs you want to target.

    As for your question about having an API to dynamically add custom types, I don't know. I would say that it is likely because most of the time you either register a new "official" type with your OS or you handle that specific type yourself because it's really only of interest to your application internals.


Log in to reply