# Apps for AppImage - any recommendations for programmers?

**URL:** <https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239>\
**Category:** Developers\
**Created:** [May 6, 2019, 7:01pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239 "2019-05-06T19:01:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SzykCech4](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/szykcech4/32/245_2.png) [@SzykCech4](https://discourse.appimage.org/u/SzykCech4)\
**Post date:** [May 6, 2019, 7:01pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239/1 "2019-05-06T19:01:52Z")

</div>

Hi  
I strugle with AppImage and I have some success (AppImage is created and my app can run from it).  
But I have strange problem: When I start my app (writen with C++ and Qt) I setup all dirs suposed to use by my app (this is due to operating systems differences). Especially I have dir to images. I setup these dirs simply related to my exe (argv[0] main function parameter). Problem is that I have message like this:

```

Error: Exception occurs!
File: /home/szyk/!-EnergoKod/!-Libs/EnergoKodEditor1/Src/LineNumberArea.cpp, in line: 68, in function: loadSettings
Error code: 6, Error message: Bookmark image not found! Missing file: /home/szyk/!-EnergoKod/Textprofan2/Installers/Linux/share/Textprofan2-x86_64.AppImage/Images/bookmark.svg
Module: Energo Kod Editor 1 library
Code: 6

```

In this case I suppose (on Linux) my exe is located in `/usr/bin` and images are in `/usr/share/Textprofan2/Images`  
I want to write my app properly so I want to know how should I setup my internaly used dirs.

So my question is:  
How shoud I access my app resources? In case it is working inside AppImage package. It require some special hanling? Or I lame in my code?

Best regards  
Szyk Cech

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [May 9, 2019, 3:41pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239/2 "2019-05-09T15:41:08Z")

</div>

Hi and welcome.

You could use QCoreApplication::applicationDirPath()  
and construct a _relative_ path to your resources from there.

[http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath](http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath)

---

<div class="post-metadata">

**Author:** ![SzykCech4](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/szykcech4/32/245_2.png) [@SzykCech4](https://discourse.appimage.org/u/SzykCech4)\
**Post date:** [May 9, 2019, 6:13pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239/3 "2019-05-09T18:13:22Z")

</div>

Thank you! You are avesome expert!!!

---

<div class="post-metadata">

**Author:** ![SzykCech4](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/szykcech4/32/245_2.png) [@SzykCech4](https://discourse.appimage.org/u/SzykCech4)\
**Post date:** [May 20, 2019, 7:37pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239/4 "2019-05-20T19:37:51Z")

</div>

Your solution cover cases:

1. when I run my app from AppImage package
2. when I run my app from sources (from `/usr/local/bin` dir)
3. when user use custom command e.g.: `cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release`

But it does not cover one importand case:  
4) compile from Ide in debug mode and run without install. In this case relay on exe position is useless.

Do you have any advices how to manage 4. case?

I can see two solutions:  
I. Add function which search some default directories (e.g.: `/usr/share` , `/usr/local/share` , `../share` )  
II. Create `../share/MyApp` dir above build dir

But I don’t know what is “recomended” way…

---

<div class="post-metadata">

**Author:** ![SzykCech4](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/szykcech4/32/245_2.png) [@SzykCech4](https://discourse.appimage.org/u/SzykCech4)\
**Post date:** [May 22, 2019, 8:13pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239/5 "2019-05-22T20:13:48Z")

</div>

> But it does not cover one importand case:  
> 4) compile from Ide in debug mode and run without install. In this case relay on exe position is useless.

I found the solution in Qt: Let assume we have `/usr/local/share/APP_NAME/Images` dir. In order to access it properly we have to set our internal directories with `QStandardPaths::locate` function. This function search `~/.local/share`, `/usr/local/share`, `/usr/share` dirs in order to find dirs or files given by parameter. The function is so kind that it properly handle subdirs like: `gProgramName + '/' + QStringLiteral("Images")`. So if you want to have reliable access to the images try some thing like this:

```
QString Application::findSharedPath(QString aSubPath)
{
    if(aSubPath[0] == '/')
        aSubPath = aSubPath.mid(1);

    QString lInstallBasePath(gPath(QCoreApplication::applicationDirPath()));
    QString lRelatedSharePath = QStringLiteral("%1/share/%2").arg(lInstallBasePath).arg(gBaseName(QCoreApplication::applicationFilePath()));
    QString lPath = lRelatedSharePath + '/' + aSubPath;
    if(!QFileInfo::exists(lPath))
        lPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, gProgramName + '/' + aSubPath, QStandardPaths::LocateDirectory);
    if(!QFileInfo::exists(lPath))
    {
        lPath = lRelatedSharePath + '/' + aSubPath;
        NOTIFY_WARNING(tr("Path not found! Missing path: %1").arg(lPath), gComponent, eErrorCode::eFileDoesNotExists);
    }
    return lPath;
}

```

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [August 4, 2019, 4:07pm UTC](https://discourse.appimage.org/t/apps-for-appimage-any-recommendations-for-programmers/1239/6 "2019-08-04T16:07:50Z")

</div>

Hello, to help you further It would be very helpful if you could post a link to your source code, ideally on GitHub or GitLab. Thank you very much.
