How to load file from resource.



  • Hi,

    I would like to know how to load a dwg file from qrc.
    My qrc is :

    <RCC>
        <qresource prefix="/resources/res">
            <file>../res/mediacad.lin</file>
            <file>../res/paperFrozen.png</file>
            <file>../res/paperSun.png</file>
            <file>../res/filter.png</file>
            <file>../res/freeze.png</file>
            <file>../res/layer.png</file>
            <file>../res/lightOff.png</file>
            <file>../res/lightOn.png</file>
            <file>../res/locked.png</file>
            <file>../res/print.png</file>
            <file>../res/sun.png</file>
            <file>../res/unlocked.png</file>
            <file>../res/unprint.png</file>
            <file>../res/dropDown.png</file>
            <file>../res/line.dwg</file>
            <file>../res/mediacad.pat</file>
            <file>../res/line.dwg</file>
            <file>../res/mediacad.lin</file>
        </qresource>
    </RCC>
    

    I try to load the dwg using ertenal library but the program crash in notify in my core application.
    But it works with a non resource file.

    m_pDatabase = ((MdCoreApplication*)qApp)->readFile(OD_T(":/resources/res/line.dwg"));
    

    I made

    Q_INIT_RESOURCE(resources);
    

    But the problem is not solved.
    I have no problem for icons. So what i do wrong ?
    Thanks.
    (sorry for my bad english)


  • Moderators

    @Roy44 said:

    I try to load the dwg using ertenal library but the program crash in notify in my core application.

    where does it crash exactly. Please show some code around the point where it crashes.

    But it works with a non resource file.

    what do you mean? When you simply do not try to access a file from the resource file? Or even remove the resource file from your project?



  • @Roy44 said:

    I try to load the dwg using ertenal library but the program crash in notify in my core application.
    But it works with a non resource file.

    m_pDatabase = ((MdCoreApplication*)qApp)->readFile(OD_T(":/resources/res/line.dwg"));
    

    What happens in the readFile method? Is this directed to the external library?
    The resource handling is very Qt specific and 3rd party libraries will not understand the "qrc:/..."-Path if they are not Qt based und do not use Qt's own file handling classes.



  • This post is deleted!


  • Thanks for your answer.
    ReadFile comes from external non Qt library.



  • @Roy44
    Does your 3rd party library provide any read-method that accepts anything else than a filename? Perhaps you can read the resource as byte array and pass it to the library...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.