[SOLVED] How to make Qt include source files/folders in compiled file? C++



  • I'm writing a program that desperately needs to be independent of my personal file system. I need the image files I'm using to be referencable from within the code, no matter where the application is located. Is there a way to make the compiled application include these folders? How would I locate them if I'm programming on a Mac in C++? Thank you for any help you can provide, I'm well versed in the basics of programming, but I have issues with these more advanced things.



  • Have you gone through "Resource system":http://developer.qt.nokia.com/doc/qt-4.8/resources.html

    Or if you dont want to use it, you may use the relative path. :)



  • Beautiful! I could kiss you! That's EXACTLY what I was hoping for and looking for. <3<3



  • ;) Happy Coding ... And may be you could add 'Solved' to the post title...



  • Can I ask my question here?

    I want to add HelpCollectionfiles (qhc- and qch-files) to a qrc-file. But is this possible.

    My application can't find the files it says, although I specified them in the right way.



  • [quote author="Woody" date="1336463595"]I want to add HelpCollectionfiles (qhc- and qch-files) to a qrc-file. But is this possible.[/quote]I hope, it is possible. Well, i am curious to know the result..

    [quote]
    My application can't find the files it says, although I specified them in the right way.[/quote] Are you sure!!??



  • [quote author="Rahul Das" date="1336498945"]
    [quote]
    My application can't find the files it says, although I specified them in the right way.[/quote] Are you sure!!??

    [/quote]

    Yes, added them trough Qt-creator, which seems to me the best way to do it.



  • Are you using [[doc:QHelpEngine]] ??



  • Yes i do.
    Still have the problem that it doesn't show me the helpfiles. (if i use resources, using absolute path works fine though)



  • Well we can now only help you when you show us the contents of your .qrc file and the source portion that tries to load from the resource. Did you add the qrc to the RESOURCES variable in the pro file? (QtCreator should've done that but you never know.)



  • My qrc-file
    @<RCC>
    <qresource prefix="/help">
    <file alias="helpcollection">doc/athleticsmanager.qhc</file>
    <file>doc/athleticsmanager.qch</file>
    </qresource>
    </RCC>@

    My pro-file
    @RESOURCES +=
    help.qrc@

    Since a qhc-file is not readable I cannot show you that content, I can however show you a glimps of the qhcp-file
    @<?xml version="1.0" encoding="UTF-8"?>
    <QHelpCollectionProject version="1.0">
    <assistant>
    <title>AthleticsManager Help</title>
    <applicationIcon>images/icon.ico</applicationIcon>
    <cacheDirectory>Athleticsmanager_Dev_Help</cacheDirectory>
    <startPage>qthelp://com.athleticsmanager/doc/index.html</startPage>
    <enableDocumentationManager>false</enableDocumentationManager>
    <enableAddressBar>false</enableAddressBar>
    <enableFilterFunctionality>false</enableFilterFunctionality>
    </assistant>
    <docFiles>
    <generate>
    <file>
    <input>athleticsmanager.qhp</input>
    <output>athleticsmanager.qch</output>
    </file>
    </generate>
    <register>
    <file>athleticsmanager.qch</file>
    </register>
    </docFiles>
    </QHelpCollectionProject>@

    Calling the qhc-file:
    @void HelperDialog::initialize()
    {
    m_helpEngine = new QHelpEngine(":/help/helpcollection", this);
    m_helpEngine->setupData();
    qDebug() << "Error: " << m_helpEngine->error();
    }@



  • put @
    qDebug() << QFile::exists(":/help/helpcollection");@
    right in front at initialize() so we rule out the possibility that the resource isn't included/referenced properly.



  • It returns me a true, so i guess my file does exist then.
    The output of @qDebug() << "Error: " << m_helpEngine->error();@ gives me Error: "Cannot open collection file: :/help/helpcollection"



  • In "QHelpEngine how-to":http://qt-project.org/forums/viewthread/3965 they use qrc-files as well:

    [quote author="willypuzzle" date="1298282352"]bq. Does it work with the docs on the hard disk?
    Did you add the file to the .qrc configuration file?
    Are the files present in the resources? You can use QDir on file path “:/” to look at the contents.

    It doesn't work with docs on the hard disk because I tried to add the absolute path of .qhc file (for example: QHelpEngine("/home/willy/help.qhc")) and it doesn't work.

    I added it to .qrc configuration file and the file is present in the resources.

    I don't understand why I have to use QDir.[/quote]

    Ok it think I got it:

    [quote author="Volker" date="1298486564"]...
    Second, the more important part: You cannot use Qt resources for storing the help content. You must put it into regular files and distribute them along your application.

    The reason for the latter is simple: The compiled help files are actually SQLite databases. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the "path"), which in turn try to open that file - and will eventually fail, of course.[/quote]

    That's a pitty!



  • Hm if you desperately want to bundle everything into one file, you could of course save the help file from the resource to a temporary directory, load the help and remove the file afterwards. But only do that if you have a good reason to, normally it's even better to keep the application and such accessories (help files, translation files, multimedia) separated.



  • Well the best that could happen to me was that I could 'store' the helpcollectionfile (qhc) in a resourcefile (qrc). So it can easily be distributed. Cause this application is going to be used by hundreds, maybe thousands of users. And then it would be much easier to get it in just one executable.

    My colleague is coming back next week, i'll ask him if he has a decent solution. But thanks for the help anyway :) Great forums here


Log in to reply
 

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