Results 1 to 4 of 4

Thread: how to add .ttf file into resource file

  1. #1
    Join Date
    Nov 2014
    Posts
    23
    Thanks
    4

    Default how to add .ttf file into resource file

    -> I want to add arialbd.ttf file (part of FTGL library) into my project using resource file(.qrc)

    -> I have added the file into .qrc file which is shown below.

    <RCC>
    <qresource prefix="/">
    <file>arialbd.ttf</file>
    </qresource>
    </RCC>


    -> But i get the following error msg at runtime,
    FT_Stream_Open: could not open `://arialbd.ttf'

    -> Here is where i am adding the path in code
    ftgl_pixFont = new FTGLPixmapFont((const char*)"://arialbd.ttf");

    like to hear suggestions

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to add .ttf file into resource file

    FTGLPixmapFont is not a Qt API, it doesn't know about Qt resource paths, only about paths in the file system.

    You can use QFile::copy() to copy into a permanent file on disk or QTemporaryFile::createNativeFile() to do it with a temporary file.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    vinothrajendran (5th March 2015)

  4. #3
    Join Date
    Nov 2014
    Posts
    23
    Thanks
    4

    Default Re: how to add .ttf file into resource file

    QFile::copy() worked for me.....Thanks

  5. #4
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to add .ttf file into resource file

    You may attempt to bypass copying the font file from the executable to a disk and rereading the file from the disk. FTGL can read the font file from a buffer (in fact, you have tried it but mistakenly). Therefore:
    (1) open() the file in the resources (you get a QFile)
    (2) readAll() the file into a QByteArray
    (3) pass FTGL the QByteArray data(). It's char *, perhaps you would need to cast to unsigned char *.
    This way, you avoid copying on the disk.

    Another possibility is not placing the font in resources at all. Put the font in the same directory as you exe, get exe dir and read the font from there. Your app need not consist of a single exe.

Similar Threads

  1. Cannot copy js file from resource to file system
    By kalma in forum Qt Programming
    Replies: 1
    Last Post: 1st January 2015, 15:10
  2. How to add 50 MB of images to resource file ??????
    By prajnaranjan.das in forum Newbie
    Replies: 5
    Last Post: 24th December 2010, 04:56
  3. resource file
    By kavinsiva in forum Newbie
    Replies: 4
    Last Post: 18th August 2009, 22:28
  4. Resource file in Qt4.4.0
    By jml in forum Qt Tools
    Replies: 0
    Last Post: 6th May 2008, 18:01
  5. Resource file in a lib
    By Rodrigo in forum Qt Programming
    Replies: 4
    Last Post: 25th June 2007, 15:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.