Menu

#6 qGo2: locate sound files under install dir

open
nobody
None
5
2012-07-26
2007-11-30
yzhh
No

This patch target the "sound file not found" bug of qGo2.

The solution is to produce a qgo_config.h in src/ when qmake is run, which contains definition of a string RESOURCE_DIR. Other code #include this file and use QString(RESOURCE_DIR)+"/sound/xxx.wav" to construct path to sound files.

To achieve this, I modified src.pro, to specify the rule to generate qgo_config.h (run qgo_config.h.gen with conditional arguments, the condition is "whether the program is to be installed").

Now modifying installation path in src.pro (and enable installation by uncommenting the line starting with INSTALLS) and re-running qmake and make install , you should hear sounds. And it is possible to disable installation and qmake, make, to let the program get sound files from source directory.

Downside is these modification is not supported by KDevelop, and not all changes are visiable in KDevelop qmake manager. You have to write into src.pro by hand.

Note: The attachment contain a diff of changes made to files already there in src. qgo_config.h.gen should be put into CVS to make it work. qgo_config.h is generated thus should not be in CVS, but provided for convenience of understanding.

Discussion

  • yzhh

    yzhh - 2007-11-30
     
  • yzhh

    yzhh - 2007-11-30

    Logged In: YES
    user_id=1785170
    Originator: YES

    Just noticed an extra space at the end of this line (in src/src.pro):
    TARGET = ../bin/qgo2
    has prevented qgo2 binary from installing. Remove the space and it installed.

     
  • Anonymous

    Anonymous - 2008-03-26

    Logged In: YES
    user_id=743915
    Originator: NO

    Thanks very much for this. As it is beyond my understanding of building a program, I will try to add this, but i just don't know if I can make it work.

    Thanks for your commitment.

     
  • yzhh

    yzhh - 2008-03-27

    Logged In: YES
    user_id=1785170
    Originator: YES

    I strongly discourage using the method used in my patch :) I found difficult to manage installation like this - it's difficult to understand in the first place.

    I looked into another qt/kde application's source code and find 2 better ways of doing this "locating data file" thing.

    1. use QApplication::applicationDirPath() to get the path to the app executable, which is said to depend on argv[0]. Then data files path can be calculated. See: http://doc.trolltech.com/4.2/qcoreapplication.html#applicationDirPath

    2. use KStandardDirs::findResourceDir() to get data files path directly. KGlobal::dirs() returns an instance of KStandardDirs. See: http://developer.kde.org/documentation/library/3.4-api/kdecore/html/classKStandardDirs.html#a11

    The former approach may run into problems when argv[0] does not include the full path, and when the relative path from the executable to data files differ on different installations. The second approach seems to have avoided these problems but adds dependency on kdecore lib.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.