Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get file type/extension's friendly name?
QtWS25 Last Chance

Get file type/extension's friendly name?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 279 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taytoo
    wrote on last edited by
    #1

    How can I get friendly name for a given file extension e.g. temp.docx = "Microsoft Word Document"

    QMimeDatabase::preferredsuffix() just returns "docx"

    JonBJ 1 Reply Last reply
    0
    • T Taytoo

      Its returning "Word 2007 Document", whereas Windows Explorer shows "Microsoft Word Document".

      I didn't really understand the part about qt qmake Profile, does it mean that I can provide my own database for QMimeDatabase to use?

      Isn't there a Qt API that calls respective OS api to get File info e.g. SHGetFileInfo on windows?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @Taytoo said in Get file type/extension's friendly name?:

      Isn't there a Qt API that calls respective OS api to get File info e.g. SHGetFileInfo on windows?

      I think the simple answer to answer is "no". Qt tries to be cross-platform. You are asking for a Windows-specific.

      You can make the call yourself via Win API.

      Or, if you don't like what Qt is returning now, you have to re-read https://doc.qt.io/qt-5/qmimedatabase.html#details section

      Applications which want to define custom MIME types need to install an XML file into the locations searched for MIME definitions.

      You would have to produce an XML file like the example but for your docx with the comment you want, and then put it in one the directories returned from the QStandardPaths::locateAll() call they show, whatever those turn out to be under Windows. That is assuming your file there will override the Qt-supplied one for docx which you have shown, the docs don't say whether your definition for docx would indeed override the in-builts.

      1 Reply Last reply
      2
      • T Taytoo

        How can I get friendly name for a given file extension e.g. temp.docx = "Microsoft Word Document"

        QMimeDatabase::preferredsuffix() just returns "docx"

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @Taytoo
        Unless you want something more non-Qt-Windows-specific, I think you want https://doc.qt.io/qt-5/qmimetype.html#comment-prop. From the example at https://doc.qt.io/qt-5/qmimedatabase.html#details I see

          <mime-type type="application/vnd.qt.qmakeprofile">
            <comment xml:lang="en">Qt qmake Profile</comment>
            <glob pattern="*.pro" weight="50"/>
          </mime-type>
        

        so that should give you Qt qmake Profile, which is as good as it gets. Read that section; note also if you are Windows:

        If the MIME type database cannot be found on the system, as is the case on most Windows, macOS, and iOS systems, Qt will use its own copy of it.

        You'll have to see what that gives you for .docx...

        1 Reply Last reply
        1
        • T Offline
          T Offline
          Taytoo
          wrote on last edited by
          #3

          Its returning "Word 2007 Document", whereas Windows Explorer shows "Microsoft Word Document".

          I didn't really understand the part about qt qmake Profile, does it mean that I can provide my own database for QMimeDatabase to use?

          Isn't there a Qt API that calls respective OS api to get File info e.g. SHGetFileInfo on windows?

          JonBJ 1 Reply Last reply
          0
          • T Taytoo

            Its returning "Word 2007 Document", whereas Windows Explorer shows "Microsoft Word Document".

            I didn't really understand the part about qt qmake Profile, does it mean that I can provide my own database for QMimeDatabase to use?

            Isn't there a Qt API that calls respective OS api to get File info e.g. SHGetFileInfo on windows?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @Taytoo said in Get file type/extension's friendly name?:

            Isn't there a Qt API that calls respective OS api to get File info e.g. SHGetFileInfo on windows?

            I think the simple answer to answer is "no". Qt tries to be cross-platform. You are asking for a Windows-specific.

            You can make the call yourself via Win API.

            Or, if you don't like what Qt is returning now, you have to re-read https://doc.qt.io/qt-5/qmimedatabase.html#details section

            Applications which want to define custom MIME types need to install an XML file into the locations searched for MIME definitions.

            You would have to produce an XML file like the example but for your docx with the comment you want, and then put it in one the directories returned from the QStandardPaths::locateAll() call they show, whatever those turn out to be under Windows. That is assuming your file there will override the Qt-supplied one for docx which you have shown, the docs don't say whether your definition for docx would indeed override the in-builts.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved